16#ifndef __B2EXCEPTION_H__ 
   17#define __B2EXCEPTION_H__ 
  113#include "b2ppconfig.h" 
  122extern "C" void b2throw_callback();
 
  143    Exception(
const std::string& msg_ = std::string(), 
const char* file_ = 
nullptr, 
int line_ = -1)
 
  144        : msg(msg_), file(file_), line(line_) {
 
  147        int bt_size = ::backtrace(bt, 128);
 
  148        backtrace.insert(backtrace.begin(), bt, bt + bt_size);
 
 
  156    virtual const char* get_name() const noexcept { 
return "Exception"; }
 
  159    const char* 
get_file()
 const { 
return file ? file : 
"??"; }
 
  165    const std::string& 
get_msg()
 const { 
return msg; }
 
  175        Throw(
const char* file_, 
int line_) : file(file_), line(line_) {}
 
 
  184        Warning(
const char* file_, 
int line_) : file(file_), line(line_) {}
 
 
  198#define THROW Exception::Throw(__FILE__, __LINE__) 
  199#define WARNING Exception::Warning(__FILE__, __LINE__) 
  202    template <
typename T>
 
  204        std::ostringstream o;
 
 
  211    template <
typename T1, 
typename T2>
 
  213        std::ostringstream o;
 
  214        o << 
"(" << t.first << 
"," << t.second << 
")";
 
 
  222        if (indicate_location) { set_location(t); }
 
 
  228        std::cerr << 
"Warning: " << msg;
 
  229        if (indicate_location) { std::cerr << 
" File " << w.file << 
":" << w.line; }
 
  230        std::cerr << std::endl;
 
 
  235    const char* what() const noexcept
 override { 
return msg.c_str(); }
 
  238    Exception* move() noexcept {
 
  239        void* e = ::operator 
new(
sizeof(Exception));
 
  240        return ::new (e) Exception(*
this);
 
  244    void destroy() noexcept { 
delete this; }
 
  247    void throw_self() { 
throw *
this; }
 
  251    void set_msg(
const std::string& msg_) { msg = msg_; }
 
  253    void set_location(
const Throw& t) {
 
  258    static bool indicate_location;
 
  265    std::vector<void*> backtrace;
 
 
  269inline std::ostream& operator<<(std::ostream& out, 
const Exception& exception) {
 
  270    out << exception.get_name() << 
": " << exception.get_msg();
 
  275template <const 
char* NAME>
 
  279          const std::string& msg_ = std::string(), 
const char* file_ = 
nullptr, 
int line_ = -1)
 
  282    const char* name() 
const noexcept { 
return typeid(
GenericException).name(); }
 
  284    const char* get_name() 
const noexcept override { 
return NAME; }
 
  286    template <
typename T>
 
  304    void destroy() 
noexcept { 
delete this; }
 
  306    void throw_self() { 
throw *
this; }
 
 
  310extern const char UnimplementedError_name[];
 
  316extern const char KeyError_name[];
 
  322extern const char TypeError_name[];
 
  327extern const char ValueError_name[];
 
  332extern const char IOError_name[];
 
  337extern const char DBError_name[];
 
  342extern const char SizeError_name[];
 
  348extern const char ConvergenceError_name[];
 
  351extern const char OutOfMemoryError_name[];
 
  354extern const char KeyboardInterrupt_name[];
 
  357extern const char SystemError_name[];
 
  360extern const char LoggingError_name[];
 
  365extern const char PythonError_name[];
 
  374template <
typename R, 
typename T>
 
  375inline R static_cast_check(T t, std::string msg = std::string()) {
 
  376    R r = 
dynamic_cast<R
>(t);
 
  381template <
typename R, 
typename T>
 
  382inline R static_cast_check(T t, std::string mgs = std::string()) {
 
  383    return static_cast<R
>(t);
 
#define THROW
Definition b2exception.H:198
 
Definition b2exception.H:131
 
Exception & operator<<(const T &t)
Definition b2exception.H:203
 
const char * name() const noexcept
Definition b2exception.H:154
 
const std::string & get_backtrace(int start_level=1) const
Definition b2exception.C:47
 
int get_line() const
Definition b2exception.H:162
 
const std::string & get_msg() const
Definition b2exception.H:165
 
Exception(const std::string &msg_=std::string(), const char *file_=nullptr, int line_=-1)
Definition b2exception.H:143
 
Exception & operator<<(const std::pair< T1, T2 > &t)
Definition b2exception.H:212
 
const char * get_file() const
Definition b2exception.H:159
 
void operator<<(const Throw &t)
Definition b2exception.H:221
 
void operator<<(const Warning &w)
Definition b2exception.H:227
 
Definition b2exception.H:276
 
Contains the base classes for implementing Finite Elements.
Definition b2boundary_condition.H:32
 
GenericException< IOError_name > IOError
Definition b2exception.H:335
 
GenericException< ValueError_name > ValueError
Definition b2exception.H:330
 
GenericException< KeyError_name > KeyError
Definition b2exception.H:320
 
GenericException< SizeError_name > SizeError
Definition b2exception.H:346
 
GenericException< PythonError_name > PythonError
Definition b2exception.H:371
 
GenericException< TypeError_name > TypeError
Definition b2exception.H:325
 
GenericException< SystemError_name > LoggingError
Definition b2exception.H:363
 
GenericException< UnimplementedError_name > UnimplementedError
Definition b2exception.H:314
 
GenericException< DBError_name > DBError
Definition b2exception.H:340
 
Definition b2exception.H:174
 
Definition b2exception.H:183