Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
assertion.C File Reference

This file contains the implementation for handling assertion failures. More...

#include "roccom_assertion.h"
#include <cstdlib>
#include <iostream>
#include <cstdio>
Include dependency graph for assertion.C:

Go to the source code of this file.

Functions

static COM_BEGIN_NAME_SPACE void _standard_error_handler (const char *what, const char *expr, const char *file, int line, const char *msg)
 
void assertion_fail (const char *expr, const char *file, int line, const char *msg)
 Default error handler. More...
 
Failure_behaviour set_error_behaviour (Failure_behaviour eb)
 Controls the behavior when an assertion fails. More...
 
Failure_function set_error_handler (Failure_function handler)
 Sets the handler for assertion-failures. More...
 

Variables

static Failure_function _error_handler = _standard_error_handler
 
static Failure_behaviour _error_behaviour = ABORT
 

Detailed Description

This file contains the implementation for handling assertion failures.

See Also
roccom_assertion.h

Definition in file assertion.C.

Function Documentation

static COM_BEGIN_NAME_SPACE void _standard_error_handler ( const char *  what,
const char *  expr,
const char *  file,
int  line,
const char *  msg 
)
static

Definition at line 47 of file assertion.C.

52 {
53  std::cerr << "ROCCOM error: " << what << " violation!" << std::endl
54  << "Expr: " << expr << std::endl
55  << "File: " << file << std::endl
56  << "Line: " << line << std::endl;
57  if ( msg != 0)
58  std::cerr << "Explanation:" << msg << std::endl;
59 }
void assertion_fail ( const char *  expr,
const char *  file,
int  line,
const char *  msg 
)

Default error handler.

Definition at line 71 of file assertion.C.

75 {
76  extern void printStackBacktrace();
77 
78  (*_error_handler)("assertion", expr, file, line, msg);
79  printStackBacktrace(); // Print stack backtrace
80  switch (_error_behaviour) {
81  case ABORT:
82  abort();
83  case EXIT:
84  exit(1); // EXIT_FAILURE
85  case EXIT_WITH_SUCCESS:
86  exit(0); // EXIT_SUCCESS
87  case CONTINUE:
88  ;
89  }
90 }
COM_BEGIN_NAME_SPACE void printStackBacktrace()
Print the stack backtrace.
static Failure_behaviour _error_behaviour
Definition: assertion.C:66
Failure_behaviour set_error_behaviour ( Failure_behaviour  eb)

Controls the behavior when an assertion fails.

Definition at line 93 of file assertion.C.

94 {
96  _error_behaviour = eb;
97  return result;
98 }
Failure_behaviour
Behavior of failures.
static Failure_behaviour _error_behaviour
Definition: assertion.C:66
Failure_function set_error_handler ( Failure_function  handler)

Sets the handler for assertion-failures.

Definition at line 104 of file assertion.C.

105 {
107  _error_handler = handler;
108  return( result);
109 }
void(* Failure_function)(const char *, const char *, const char *, int, const char *)
Function type for error handlers.
static Failure_function _error_handler
Definition: assertion.C:65

Variable Documentation

Failure_behaviour _error_behaviour = ABORT
static

Definition at line 66 of file assertion.C.

Referenced by assertion_fail(), and set_error_behaviour().

Failure_function _error_handler = _standard_error_handler
static

Definition at line 65 of file assertion.C.

Referenced by set_error_handler().