Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
assertion.C
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: assertion.C,v 1.12 2008/12/06 08:43:25 mtcampbe Exp $
24 
29 /* Author: Xiangmin Jiao
30  * Created: Jan. 10, 2001
31  * Last modified: May 8, 2001
32  */
33 
34 #include "roccom_assertion.h"
35 #include <cstdlib>
36 #include <iostream>
37 #include <cstdio>
38 
39 COM_BEGIN_NAME_SPACE
40 
41 #ifndef DOXYGEN_SHOULD_SKIP_THIS
42 
43 // standard error handlers
44 // -----------------------
45 static
46 void
47 _standard_error_handler( const char* what,
48  const char* expr,
49  const char* file,
50  int line,
51  const char* msg )
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 }
60 
61 
62 // default handler settings
63 // ------------------------
64 static Failure_function
67 
68 // failure functions
69 // -----------------
70 void
71 assertion_fail( const char* expr,
72  const char* file,
73  int line,
74  const char* msg )
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 }
91 
94 {
96  _error_behaviour = eb;
97  return result;
98 }
99 
100 
101 // error handler set functions
102 // ---------------------------
105 {
107  _error_handler = handler;
108  return( result);
109 }
110 
111 #endif
112 
113 COM_END_NAME_SPACE
114 
115 
116 
117 
118 
119 
Failure_function set_error_handler(Failure_function handler)
Sets the handler for assertion-failures.
Definition: assertion.C:104
Failure_behaviour set_error_behaviour(Failure_behaviour eb)
Controls the behavior when an assertion fails.
Definition: assertion.C:93
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
Failure_behaviour
Behavior of failures.
COM_BEGIN_NAME_SPACE void printStackBacktrace()
Print the stack backtrace.
void assertion_fail(const char *, const char *, int, const char *)
Default error handler.
Definition: assertion.C:71
static COM_BEGIN_NAME_SPACE void _standard_error_handler(const char *what, const char *expr, const char *file, int line, const char *msg)
Definition: assertion.C:47
This file contains a set of routines for error assertion.
static Failure_behaviour _error_behaviour
Definition: assertion.C:66