rcolyer.net
RC Lib  Version 202403231100
Classes | Namespaces | Macros | Variables
Errors.h File Reference

Provides informative exception handling. More...

#include "RCconfig.h"
#include "Types.h"
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <typeinfo>

Go to the source code of this file.

Classes

class  RC::ErrorMsg
 An exception class that records where the exception was thrown and provides a stack trace. More...
 
class  RC::ErrorMsgFatal
 A subtype of RC::ErrorMsg for Fatal errors. More...
 
class  RC::ErrorMsgNull
 A subtype of RC::ErrorMsg for Null errors. More...
 
class  RC::ErrorMsgBounds
 A subtype of RC::ErrorMsg for Bounds errors. More...
 
class  RC::ErrorMsgMemory
 A subtype of RC::ErrorMsg for Memory errors. More...
 
class  RC::ErrorMsgCast
 A subtype of RC::ErrorMsg for Bad Cast errors. More...
 
class  RC::ErrorMsgFile
 A subtype of RC::ErrorMsg for File related errors. More...
 
class  RC::ErrorMsgNet
 A subtype of RC::ErrorMsg for Networking related errors. More...
 
class  RC::Segfault
 A static class for catching and throwing segfaults. More...
 

Namespaces

 RC
 

Macros

#define RC_MAKE_ERROR_TYPE(Type)
 Creates new RC::ErrorMsg subtypes. More...
 
#define Throw_RC_Error(err)   throw RC::ErrorMsg(err, __FILE__, __LINE__)
 Use this to throw an RC:ErrorMsg exception. More...
 
#define Throw_RC_Type(Type, err)   throw RC::ErrorMsg##Type(err, __FILE__, __LINE__)
 Use this to throw an RC:ErrorMsg subtype exception. More...
 
#define Catch_RC_Error()   catch (RC::ErrorMsgFatal& err) { fprintf(stderr, "Fatal Error: %s\n", err.what()); exit(-1); } catch (RC::ErrorMsg& err) { fprintf(stderr, "Error: %s\n", err.what()); }
 Place after a try block to catch RC errors and print the error text. More...
 
#define Catch_RC_Error_Exit()   catch (RC::ErrorMsg& err) { fprintf(stderr, "Error: %s\n", err.what()); exit(-1); }
 Place after a try block to catch RC errors, print the error text, and exit.
 

Variables

const size_t RC::ErrorMsg_text_size = 4095
 The maximum size of the char array returned by ErrorMsg::what() and ErrorMsg::GetError(), including the null.
 
const size_t RC::ErrorMsg_type_bufsize = 256
 The maximum size of the char array returned by ErrorMsg::GetType(), including the null.
 

Detailed Description

Provides informative exception handling.

Macro Definition Documentation

◆ Catch_RC_Error

#define Catch_RC_Error ( )    catch (RC::ErrorMsgFatal& err) { fprintf(stderr, "Fatal Error: %s\n", err.what()); exit(-1); } catch (RC::ErrorMsg& err) { fprintf(stderr, "Error: %s\n", err.what()); }

Place after a try block to catch RC errors and print the error text.

Note: Exits on ErrorMsgFatal with return value -1.

◆ RC_MAKE_ERROR_TYPE

#define RC_MAKE_ERROR_TYPE (   Type)
Value:
class ErrorMsg##Type : virtual public RC::ErrorMsg {\
public:\
/** \brief The default constructor. */ \
/** Use the convenience macro Throw_RC_Type(Type, "Reason"); */ \
ErrorMsg##Type(const char* new_err_msg, const char* filename = "",\
int line_number = 0)\
: RC::ErrorMsg(new_err_msg, filename, line_number) {\
snprintf(type_msg, ErrorMsg_type_bufsize, #Type);\
}\
};
An exception class that records where the exception was thrown and provides a stack trace.
Definition: Errors.h:60
const size_t ErrorMsg_type_bufsize
The maximum size of the char array returned by ErrorMsg::GetType(), including the null.
Definition: Errors.h:45

Creates new RC::ErrorMsg subtypes.

Use as: "namespace RC { RC_MAKE_ERROR_TYPE(NewType) }" to make RC::ErrorMsgNewType

◆ Throw_RC_Error

#define Throw_RC_Error (   err)    throw RC::ErrorMsg(err, __FILE__, __LINE__)

Use this to throw an RC:ErrorMsg exception.

It automatically adds the source file name and line number.

Parameters
err(const char*) The reason for the exception.

◆ Throw_RC_Type

#define Throw_RC_Type (   Type,
  err 
)    throw RC::ErrorMsg##Type(err, __FILE__, __LINE__)

Use this to throw an RC:ErrorMsg subtype exception.

It automatically adds the source file name and line number.

Parameters
TypeThe subtype. e.g. Throw_RC_Type(Null, "Reason") for ErrorMsgNull.
err(const char*) The reason for the exception.
email address
— (c) 2015