O'Reilly logo

CouchDB and PHP Web Development Beginner's Guide by Tim Juravich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — handling exceptions

Now that we can handle exceptions, let's add some code to the get_by_username function, so that we can take a deeper look at our problem.

  1. Let's open classes/user.php, and add a try...catch statement around our Sag call to make sure that we can handle any errors that occur.
    public static function get_by_username($username = null) {
    $bones = new Bones();
    $bones->couch->login(ADMIN_USER, ADMIN_PASSWORD);
    $bones->couch->setDatabase('_users');
    $user = new User();
    try {
    
    $document = $bones->couch->get('org.couchdb.user:' . $username)->body;
    $user->_id = $document->_id;
    $user->name = $document->name;
    $user->email = $document->email;
    $user->full_name = $document->full_name;
    return $user;
    } catch (SagCouchException ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required