Showing posts with label debug. Show all posts
Showing posts with label debug. Show all posts

Catching Exceptions from the Java Client Library


Just like our other client libraries, if you're using the Java client library and encounter a server error, an exception will be generated. This will cause Java to stop in its tracks and print out the contents of the exception. While this is useful for debugging, in a production application you'll probably want your application to fail gracefully, perhaps displaying a nice error message to your users.

You can do this by wrapping your code in a try block and using an catch statement:

try {
  // Do something that accesses the network
} catch (IOError e) {
    // Insert custom error handling code here.
    System.out.println(e.toString());
} catch (ServiceException e) {
    // Insert custom error handling code here.
    System.out.println(e.toString());
}

Most errors will be instances of either IOError or ServiceException, depending on the cause.

Catching Exceptions from the Python Client Library


If you're using the Python client library and encounter a server error, an exception will be generated, causing Python to stop in its tracks and print out the contents of the exception. While this is useful for debugging, in a production application you'll probably want your application to fail gracefully, perhaps displaying a nice error message to your users.

You can do this by wrapping your code in a try block and using an except statement:

try:
  # Do something that accesses the network
except gdata.service.RequestError, inst:
  response = inst[0]
  status = response['status']
  reason = response['reason']
  body = response['body']
  # Handle the error here

Other exceptions may be thrown depending on the situation. For more information, see the gdata.service documentation.

Catching Exceptions from the PHP Client Library


If you are using the PHP client library and see an error like "Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 400' in ..." What you should really do is surround your code in a try block and use a catch statement like this:
catch(Zend_Gdata_App_HttpException $exception) {
    echo "Error: " . $exception->getResponse()->getRawBody();
}
Usually this will print a more informative message describing the reason for failure.

Enable Request Debugging in PHP client library


$service->enableRequestDebugLogging('/tmp/foo.txt');