2 #ifndef WIBBLE_EXCEPTION_H
3 #define WIBBLE_EXCEPTION_H
109 static std::vector< std::string > &
context() {
112 s_context =
new std::vector< std::string >();
116 template<
typename O >
153 void addContext(
const std::string& c)
throw () { m_context.push_back(c); }
156 if (m_context.empty())
157 return "no context information available";
159 std::stringstream res;
160 std::copy( m_context.begin(), m_context.end(),
161 std::ostream_iterator< std::string >( res,
", \n " ) );
162 std::string r = res.str();
163 return std::string( r, 0, r.length() - 7 );
166 const std::vector<std::string>&
context()
const throw ()
190 virtual const char*
type()
const throw () {
return "Generic"; }
193 virtual std::string
desc()
const throw ()
195 return "an unspecified problem happened; if you see this message, please report a bug to the maintainer";
205 virtual const std::string&
fullInfo()
const throw ()
207 if (m_formatted.empty())
208 m_formatted =
desc() +
". Context:\n "
213 virtual const char*
what()
const throw () {
return fullInfo().c_str(); }
230 virtual const char*
type()
const throw () {
return "Interrupted"; }
247 virtual const char*
type()
const throw () {
return "WaitInterrupted"; }
260 Generic(context), m_error(error) {}
263 virtual const char*
type()
const throw () {
return "Consistency"; }
265 virtual std::string
desc()
const throw ()
268 return "consistency check failed";
279 virtual std::string
typeinfo()
const throw() {
return "unknown types"; }
280 virtual std::string
desc()
const throw() {
281 return std::string(
"bad cast: " ) +
typeinfo();
286 template<
typename From,
typename To >
289 BadCastExt(
const std::string &error = std::string() ) throw()
293 virtual std::string
typeinfo()
const throw() {
return std::string(
"from " )
294 +
typeid( From ).name()
296 +
typeid( To ).name(); }
319 virtual const char*
type()
const throw () {
return "OutOfRange"; }
324 virtual std::string
desc()
const throw () {
return m_var_desc +
" out of range"; }
356 const std::string&
context)
throw ()
362 virtual C
val()
const throw () {
return m_val; }
370 virtual const char*
type()
const throw ()
372 return "ValOutOfRange<>";
375 virtual std::string
desc()
const throw ();
405 virtual const char*
type()
const throw () {
return "System"; }
408 virtual int code()
const throw () {
return m_errno; }
411 virtual std::string
desc()
const throw ();
426 File(
const std::string& name,
const std::string&
context)
throw () :
427 System(
context), m_name(name) {}
430 virtual const char*
type()
const throw () {
return "File"; }
int m_errno
Definition: exception.h:399
virtual std::string typeinfo() const
Definition: exception.h:293
Store context information for an exception.
Definition: exception.h:136
virtual C sup() const
Get the maximum allowed value for this index.
Definition: exception.h:367
Base class for exceptions for file I/O.
Definition: exception.h:420
static std::vector< std::string > & context()
Definition: exception.h:109
C m_sup
Definition: exception.h:349
~OutOfRange()
Definition: exception.h:317
virtual const char * type() const
Get a string tag identifying the exception type.
Definition: exception.h:230
virtual const char * type() const
Get a string tag identifying the exception type.
Definition: exception.h:190
virtual std::string desc() const
Get the description of the error code.
virtual ~Generic()
Definition: exception.h:187
static void copyContext(O out)
Definition: exception.h:117
~Consistency()
Definition: exception.h:261
virtual const char * type() const
Get a string tag identifying the exception type.
Definition: exception.h:430
ValOutOfRange(const std::string &var_desc, C val, C inf, C sup, const std::string &context)
Construct the exception; minBound and maxBound are the bounds of the valid index range (inclusive)...
Definition: exception.h:355
virtual int code() const
Get the system error code associated to the exception.
Definition: exception.h:408
virtual std::string desc() const
Get a string describing what happened that threw the exception.
Definition: exception.h:193
Generic()
Definition: exception.h:185
Exception thrown when some consistency check fails.
Definition: exception.h:254
BadCast(const std::string &context)
Definition: exception.h:275
Exception thrown when index checking fails.
Definition: exception.h:344
virtual C inf() const
Get the minimum allowed value for this index.
Definition: exception.h:365
Base class for all exceptions.
Definition: exception.h:179
ListIterator< List > begin(List l)
Definition: list.h:420
virtual std::string desc() const
Get a string describing what happened that threw the exception.
Definition: exception.h:280
void(* old)()
Definition: exception.h:99
#define assert_eq(x, y)
Definition: test.h:33
virtual std::string desc() const
Get the description of the error code.
Definition: exception.h:432
Context()
Definition: exception.h:142
virtual std::string desc() const
Get a string describing what happened that threw the exception.
Definition: exception.h:265
Definition: exception.h:273
std::string m_context
Definition: exception.h:121
~File()
Definition: exception.h:428
virtual const char * type() const
Get a string tag identifying the exception type.
Definition: exception.h:405
Exception thrown when some long event is interrupted by an external event (like a system call being i...
Definition: exception.h:224
Exception thrown when some system wait is interrupted by a signal.
Definition: exception.h:241
Consistency(const std::string &context, const std::string &error=std::string())
Definition: exception.h:259
std::string m_formatted
Definition: exception.h:182
static std::vector< std::string > * s_context
Definition: exception.h:107
~AddContext()
Definition: exception.h:129
virtual const char * type() const
Get a string tag identifying the exception type.
Definition: exception.h:319
Interrupted()
Definition: exception.h:227
AddContext(std::string s)
Definition: exception.h:123
virtual std::string var_desc() const
Get a short description of the variable that has been checked.
Definition: exception.h:322
Install an unexpected handler for the duration of its scope.
Definition: exception.h:96
Interrupted(const std::string &context)
Definition: exception.h:228
void DefaultUnexpected()
Basic unexpected handler.
Definition: exception.cpp:69
WaitInterrupted(const std::string &context)
Definition: exception.h:244
C m_val
Definition: exception.h:347
File(const std::string &name, const std::string &context)
Definition: exception.h:426
C m_inf
Definition: exception.h:348
virtual std::string desc() const
Get a string describing what happened that threw the exception.
Definition: exception.h:324
std::string formatContext() const
Definition: exception.h:154
~BadCastExt()
Definition: exception.h:292
virtual C val() const
Get the value that caused the index to go out-of-bounds.
Definition: exception.h:363
Context(const std::string &context)
Definition: exception.h:147
virtual std::string desc() const
Get a string describing what happened that threw the exception.
virtual std::string typeinfo() const
Definition: exception.h:279
Exception thrown when some value is out of range.
Definition: exception.h:309
std::string m_name
Definition: exception.h:423
Definition: exception.h:106
InstallUnexpected(void(*func)()=DefaultUnexpected)
Definition: exception.cpp:76
virtual const char * type() const
Get a string tag identifying the exception type.
Definition: exception.h:247
OutOfRange(const std::string &var_desc, const std::string &context)
Definition: exception.h:315
std::vector< std::string > m_context
Definition: exception.h:139
~BadCast()
Definition: exception.h:278
virtual const char * type() const
Get a string tag identifying the exception type.
Definition: exception.h:370
Generic(const std::string &context)
Definition: exception.h:186
BadCastExt(const std::string &error=std::string())
Definition: exception.h:289
const std::vector< std::string > & context() const
Definition: exception.h:166
std::string m_var_desc
Definition: exception.h:312
virtual const char * what() const
Definition: exception.h:213
virtual const char * type() const
Get a string tag identifying the exception type.
Definition: exception.h:263
virtual const std::string & fullInfo() const
Format in a string all available information about the exception.
Definition: exception.h:205
ListIterator< List > end(List)
Definition: list.h:425
~InstallUnexpected()
Definition: exception.cpp:81
Definition: exception.h:287
void addContext(const std::string &c)
Definition: exception.h:153
Base class for system exceptions.
Definition: exception.h:396