35 #ifndef KJB_EXCEPTION_H
36 #define KJB_EXCEPTION_H
38 #include <l/l_sys_err.h>
39 #include <l/l_sys_str.h>
40 #include <l/l_string.h>
41 #include <boost/preprocessor/seq.hpp>
46 #define KJB_THROW(ex) throw ex(__FILE__, __LINE__)
48 #define KJB_THROW_2(ex, msg) throw ex(msg, __FILE__, __LINE__)
56 #define KJB_THROW_3(ex, fmt, params) \
59 char buffer[ERROR_MESS_BUFF_SIZE]; \
60 kjb_c::kjb_sprintf(buffer, ERROR_MESS_BUFF_SIZE, fmt, \
61 BOOST_PP_SEQ_ENUM(params)); \
62 throw ex(buffer, __FILE__, __LINE__); \
72 kjb::throw_kjb_error( "", __FILE__, __LINE__ ); \
78 #define ETX_2(a, msg) \
83 kjb::throw_kjb_error(msg, __FILE__, __LINE__); \
94 kjb::throw_kjb_error( "Null result", \
95 __FILE__, __LINE__ ); \
101 #define IFT(a, ex, msg) \
106 KJB_THROW_2(ex, msg); \
112 #define IFTD(a, ex, msg, params) \
117 KJB_THROW_3(ex, msg, params); \
137 Exception(
const char* msg,
const char* file=0,
unsigned line=0);
141 Exception(
const std::string& msg,
const char* file=0,
unsigned line=0);
158 const char*
what()
const throw()
160 return m_msg.c_str();
187 virtual void print()
const;
240 bool newline =
false,
241 int status = EXIT_FAILURE
266 KJB_error(
const char* msg,
const char* file=0,
unsigned line=0);
270 KJB_error(
const std::string& msg,
const char* file=0,
unsigned line=0);
296 const std::string& msg,
328 Runtime_error(
const char* msg,
const char* file=0,
unsigned line=0);
333 const std::string& msg,
365 Cant_happen(
const char* msg,
const char* file=0,
unsigned line=0);
368 Cant_happen(
const std::string& msg,
const char* file=0,
unsigned line=0);
388 const std::string& msg,
414 const std::string& msg,
438 const std::string& msg,
457 Divide_by_zero(
const char* msg,
const char* file=0,
unsigned line=0);
462 const std::string& msg,
485 const std::string& msg,
500 IO_error(
const char* file,
unsigned line);
503 IO_error(
const char* msg,
const char* file=0,
unsigned line=0);
507 IO_error(
const std::string& msg,
const char* file=0,
unsigned line=0);
525 Result_error(
const char* msg,
const char* file=0,
unsigned line=0);
530 Result_error(
const std::string& msg,
const char* file=0,
unsigned line=0);
547 const char* dependency,
555 const std::string& dependency,
572 const std::string& msg,
587 const std::string& option,
650 void throw_kjb_error(
const char* msg,
const char* file,
unsigned line);
Object thrown when serialization or deserialization fails.
Definition: l_exception.h:473
Base class of all exceptions in the jwsc++ library.
Definition: l_exception.h:132
const char * get_file() const
Returns the file name where the Exception occurred.
Definition: l_exception.h:165
virtual ~Resource_exhaustion()
Deletes exception.
Definition: l_exception.h:644
Object thrown when an index argument exceeds the size of a container.
Definition: l_exception.h:399
virtual ~Missing_option()
Deletes exception.
Definition: l_exception.h:593
Serialization_error(const char *file, unsigned line)
Constructs an Exception caused by a serialization error.
Definition: l_exception.cpp:527
Object thrown when an argument is of the wrong size or dimensions.
Definition: l_exception.h:426
virtual ~Option_exception()
Deletes exception.
Definition: l_exception.h:578
std::string get_details() const
Return string containing filename, line number, and message.
Definition: l_exception.cpp:80
unsigned get_line() const
Returns the line number near where the Exception occurred.
Definition: l_exception.h:172
virtual ~Exception()
Deletes an Exception.
Definition: l_exception.h:148
Object thrown for exceptions related to command-line options.
Definition: l_exception.h:567
virtual ~Result_error()
Deletes a Result error.
Definition: l_exception.h:534
Object thrown when a function cannot generate a valid result.
Definition: l_exception.h:516
Object thrown if a resource allocation failed (memory, fp, etc.)
Definition: l_exception.h:635
Object thrown if stack is empty and popped.
Definition: l_exception.h:623
virtual ~Runtime_error()
Deletes a Runtime_error.
Definition: l_exception.h:339
void throw_kjb_error(const char *msg, const char *file, unsigned line)
Definition: l_exception.cpp:748
Runtime_error(const char *file, unsigned line)
Constructs a runtime exception.
Definition: l_exception.cpp:324
virtual void print_details() const
Definition: l_exception.cpp:119
const std::string & get_msg() const
Returns the error message for the Exception.
Definition: l_exception.h:152
virtual ~KJB_error()
Deletes a KJB_error.
Definition: l_exception.h:274
virtual void print_abort() const
Definition: l_exception.cpp:137
Result_error(const char *file, unsigned line)
Constructs an Exception caused by a function generating an invalid result.
Definition: l_exception.cpp:605
const char * what() const
Returns the error message for the Exception.
Definition: l_exception.h:158
Index_out_of_bounds(const char *file, unsigned line)
Constructs an Exception caused by attempting to access an index outside the bounds of a collection...
Definition: l_exception.cpp:236
KJB_error(const char *msg, const char *file=0, unsigned line=0)
Constructs Exception caused by an error in the KJB C library.
Definition: l_exception.cpp:210
Stack_underflow(const char *file=0, unsigned line=0)
Constructs an Exception caused by a stack underflow.
Definition: l_exception.cpp:714
virtual ~Cant_happen()
Deletes a Cant_happen.
Definition: l_exception.h:371
virtual void print_details_abort() const
Definition: l_exception.cpp:155
virtual ~Divide_by_zero()
Deletes a Divide_by_zero.
Definition: l_exception.h:468
Resource_exhaustion(const char *file=0, unsigned line=0)
Constructs an Exception caused by a stack underflow. */.
Definition: l_exception.h:639
Missing_dependency(const char *file, unsigned line)
Constructs an Exception caused by a missing dependency.
Definition: l_exception.cpp:636
Dimension_mismatch(const char *file, unsigned line)
Constructs an Exception caused by dimension mismatch.
Definition: l_exception.cpp:445
Option_exception(const std::string &msg, const char *file=0, unsigned line=0)
Constructs an Exception related to command-line options.
Definition: l_exception.cpp:672
Exception often thrown when wrapped C functions return error codes.
Definition: l_exception.h:262
Stack_overflow(const char *file=0, unsigned line=0)
Constructs an Exception caused by a stack overflow.
Definition: l_exception.cpp:707
Cant_happen Cant_happen_exception
Definition: l_exception.h:597
Object thrown when an division is attempted with a zero divisor.
Definition: l_exception.h:450
Object thrown when an obligatory command-line option is absent.
Definition: l_exception.h:582
virtual ~Stack_underflow()
Deletes exception.
Definition: l_exception.h:630
virtual ~IO_error()
Deletes an IO error.
Definition: l_exception.h:511
unsigned m_line
Line number where the Error occurred.
Definition: l_exception.h:257
virtual ~Missing_dependency()
Deletes exception.
Definition: l_exception.h:562
virtual void print() const
Definition: l_exception.cpp:100
virtual void print_exit() const
Definition: l_exception.cpp:175
virtual void print_details_exit() const
Definition: l_exception.cpp:196
Object thrown when the program does something thought impossible.
Definition: l_exception.h:358
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
virtual ~Dimension_mismatch()
Deletes a Dimension_mismatch.
Definition: l_exception.h:444
Object thrown when attempting to use unimplemented functionality.
Definition: l_exception.h:281
Divide_by_zero(const char *file, unsigned line)
Constructs an Exception caused by dividing by zero.
Definition: l_exception.cpp:488
std::string m_msg
Message associated with the error causing the exception.
Definition: l_exception.h:251
Object thrown when input or output fails.
Definition: l_exception.h:496
Cant_happen(const char *file, unsigned line)
Ctor of Exception caused reaching presumably unreachable code.
Definition: l_exception.cpp:362
virtual ~Serialization_error()
Deletes a Serialization_error.
Definition: l_exception.h:491
Object thrown when a program lacks required resources or libraries.
Definition: l_exception.h:539
Missing_option(const std::string &option, const char *file=0, unsigned line=0)
Constructs an Exception caused by a missing command-line option.
Definition: l_exception.cpp:683
Not_implemented(const char *file, unsigned line)
Constructs an Exception caused by attempting to use un-implemented functionality. ...
Definition: l_exception.cpp:280
Illegal_argument(const char *file, unsigned line)
Ctor for passing an illegal argument to a method.
Definition: l_exception.cpp:401
Exception(const char *msg, const char *file=0, unsigned line=0)
Constructs an Exception.
Definition: l_exception.cpp:43
virtual ~Stack_overflow()
Deletes exception.
Definition: l_exception.h:619
virtual ~Index_out_of_bounds()
Deletes a Index_out_of_bounds.
Definition: l_exception.h:421
virtual ~Illegal_argument()
Deletes a Illegal_argument. */.
Definition: l_exception.h:394
Object thrown when computation fails somehow during execution.
Definition: l_exception.h:321
IO_error(const char *file, unsigned line)
Constructs an Exception caused by an IO error.
Definition: l_exception.cpp:570
Object thrown if a finite size stack is full and pushed farther.
Definition: l_exception.h:612
const char * m_file
File name where the Error occurred.
Definition: l_exception.h:254
std::string kjb_get_error()
similar to kjb_c::kjb_get_error(), but this returns std::string.
Definition: l_exception.cpp:723
virtual ~Not_implemented()
Deletes a Not_implemented.
Definition: l_exception.h:303