21 #ifndef P_EXCEPTIONS_H
22 #define P_EXCEPTIONS_H
28 #define _P_EXCEPTION_QUOTEME(x) #x
29 #define P_EXCEPTION_QUOTEME(x) _P_EXCEPTION_QUOTEME(x)
30 #define P_EXCEPTION_EXCTOR(s) ((std::string(__FILE__ "," P_EXCEPTION_QUOTEME(__LINE__) ": ") + s) + ".")
31 #define P_EX_THROW(ex,s) (throw ex(P_EXCEPTION_EXCTOR(s)))
33 class p_base_exception:
public std::exception {
35 p_base_exception(
const std::string &s):m_what(s) {}
36 virtual const char *what()
const throw() {
37 return m_what.c_str();
39 virtual ~p_base_exception() throw() {}
44 struct index_error:
public p_base_exception {
45 index_error(
const std::string &s): p_base_exception(s) {}
48 struct value_error:
public p_base_exception {
49 value_error(
const std::string &s): p_base_exception(s) {}
52 struct io_error:
public p_base_exception {
53 io_error(
const std::string &s): p_base_exception(s) {}
56 struct type_error:
public p_base_exception {
57 type_error(
const std::string &s): p_base_exception(s) {}
60 struct assertion_error:
public p_base_exception {
61 assertion_error(
const std::string &s): p_base_exception(s) {}
64 struct zero_division_error:
public p_base_exception {
65 zero_division_error(
const std::string &s): p_base_exception(s) {}
68 struct not_implemented_error:
public p_base_exception {
69 not_implemented_error(
const std::string &s): p_base_exception(s) {}
72 struct memory_error:
public p_base_exception {
73 memory_error(
const std::string &s): p_base_exception(s) {}
76 #define P_EX_ASSERT(expr) \
78 P_EX_THROW(assertion_error,"assertion error"); \