AyushP123

exception handeling

May 25th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. Xapian reports errors by throwing exceptions. For failures in things like memory allocation, you will see exceptions derived from std::exception, but exceptions related to Xapian-specific issues will be derived from Xapian::Error.
  2.  
  3. Uncaught exceptions will cause your program to terminate, so it’s wise to at least have a top-level exception handler which can catch any exceptions and report what they were. You can call the get_description() method on a Xapian::Error object to get a human readable string including all the information the object contains.
  4.  
  5. Because Xapian::Error is an abstract base class you need to catch it by reference:
  6.  
  7. try {
  8.     do_something_with_xapian();
  9. } catch (const Xapian::Error & e) {
  10.     cout << "Exception: " << e.get_description() << endl;
  11. } catch (const std::exception & e) {
  12.     cout << "Exception: " << e.what() << endl;
  13. }
Add Comment
Please, Sign In to add comment