b2api
B2000++ API Reference Manual, VERSION 4.6
 
Loading...
Searching...
No Matches
b2exception.H File Reference
#include <exception>
#include <iostream>
#include <sstream>
#include <string>
#include "b2ppconfig.h"
#include "utils/b2util.H"
Include dependency graph for b2exception.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  b2000::Exception
 
struct  b2000::Exception::Throw
 
struct  b2000::Exception::Warning
 
class  b2000::GenericException< NAME >
 

Namespaces

namespace  b2000
 Contains the base classes for implementing Finite Elements.
 

Macros

#define THROW   Exception::Throw(__FILE__, __LINE__)
 

Typedefs

typedef GenericException< UnimplementedError_name > b2000::UnimplementedError
 
typedef GenericException< KeyError_name > b2000::KeyError
 
typedef GenericException< TypeError_name > b2000::TypeError
 
typedef GenericException< ValueError_name > b2000::ValueError
 
typedef GenericException< IOError_name > b2000::IOError
 
typedef GenericException< DBError_name > b2000::DBError
 
typedef GenericException< SizeError_name > b2000::SizeError
 
typedef GenericException< SystemError_name > b2000::LoggingError
 
typedef GenericException< PythonError_name > b2000::PythonError
 

Detailed Description

A set of C++ exception classes for convenient error reporting and handling, with (if supported by the platform) support for backtraces.

Overview

In contrast to Fortran and C, error handling in C++ - and hence in the entire B2000++ source code - should be implemented making use of exceptions.

The C++ exception mechanism permits to decouple the code where an error is detected from the code that handles the error. To this end, the code that detected an error creates an object and "throws" it, while the code that handles that particular error "catches" the object. At the place where the object is caught, it can be used like any other object. Therefore the error message, the type of error, the reason, etc. are usually put in such objects.

The b2000::Exception class is fundamental to B2000++'s error handling facility. It contains:

  • A string containing the error message.
  • The file name of the file where the exception was thrown.
  • The line in the file where the exception was thrown.
  • Optional backtrace information.

Throwing Exceptions

To throw a generic Exception:

if (error)
Exception() << "Error message..." << THROW;
#define THROW
Definition b2exception.H:198

The THROW macro (also defined in b2exception.H) sets file name and line number.

Catching Exceptions

Example:

try {
...
} catch (OutOfMemoryError& e) {
std::cerr << "Out of memory: " << e.get_msg() << std::endl;
std::exit(1);
}

Backtraces

The Exception class contains support for obtaining the backtrace (list of all functions going back to the place where the exception was raised) on platforms where a recent version of the GNU C/C++ compiler and associated binutils package is used.

Pre-defined Exception Classes

In addition, a set of pre-defined specializations of b2000::Exception is defined, notably:

It is recommended to make use of these specializations where appropriate.

Macro Definition Documentation

◆ THROW

#define THROW   Exception::Throw(__FILE__, __LINE__)

Create a Throw/Warning structure with the current file name and line number. To be used as follows:

Exception() << "The message ..." << THROW;
Exception() << "The message ..." << WARNING;