Mike Dodd | 8cfa702 | 2010-11-17 11:12:26 -0800 | [diff] [blame] | 1 | /** |
| 2 | * @file op_exception.h |
| 3 | * exception base class |
| 4 | * |
| 5 | * This provide simple base class for exception object. All |
| 6 | * exception are derived from directly or indirectly from |
| 7 | * std::exception. This class are not itended to be catched |
| 8 | * in your code except at top level, derive what you want |
| 9 | * and catch derived class rather. |
| 10 | * |
| 11 | * @remark Copyright 2003 OProfile authors |
| 12 | * @remark Read the file COPYING |
| 13 | * |
| 14 | * @author Philippe Elie |
| 15 | * @author John Levon |
| 16 | */ |
| 17 | |
| 18 | #ifndef OP_EXCEPTION_H |
| 19 | #define OP_EXCEPTION_H |
| 20 | |
| 21 | #include <stdexcept> |
| 22 | #include <string> |
| 23 | |
| 24 | |
| 25 | /** |
| 26 | * exception abstract base class |
| 27 | */ |
| 28 | class op_exception : public std::exception { |
| 29 | public: |
| 30 | explicit op_exception(std::string const& msg); |
| 31 | ~op_exception() throw() = 0; |
| 32 | |
| 33 | char const * what() const throw(); |
| 34 | private: |
| 35 | std::string message; |
| 36 | }; |
| 37 | |
| 38 | |
| 39 | /** |
| 40 | * fatal exception, never catch it except at top level (likely main or |
| 41 | * gui). Intended to replace cerr << "blah"; exit(EXIT_FAILURE); by a |
| 42 | * throw op_fatal_error("blah") when returning error code is not an option |
| 43 | */ |
| 44 | struct op_fatal_error : op_exception |
| 45 | { |
| 46 | explicit op_fatal_error(std::string const & msg); |
| 47 | }; |
| 48 | |
| 49 | /** |
| 50 | * Encapsulate a runtime error with or w/o a valid errno |
| 51 | */ |
| 52 | struct op_runtime_error : std::runtime_error |
| 53 | { |
| 54 | explicit op_runtime_error(std::string const & err); |
| 55 | op_runtime_error(std::string const & err, int cerrno); |
| 56 | ~op_runtime_error() throw(); |
| 57 | }; |
| 58 | |
| 59 | |
| 60 | #endif /* !OP_EXCEPTION_H */ |