Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
roccom_exception.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: roccom_exception.C,v 1.13 2008/12/06 08:43:25 mtcampbe Exp $
24 
25 #include "roccom_exception.h"
26 #include <iostream>
27 #include <cstdio>
28 
29 #if defined(__gnu_linux__) && defined(__i386__)
30 #define TRACEBACK 1 // Define TRACEBACK on Linux and Apple
31 #endif
32 
33 #ifdef TRACEBACK
34 #include <execinfo.h> /* for backtrace (GNU glibc header) */
35 #endif
36 
37 COM_BEGIN_NAME_SPACE
38 
41 #if !defined( __CHARMC__) && defined(TRACEBACK)
42  const int max_stack=64;
43  void *stackPtrs[max_stack];
44 
45  int levels=backtrace(stackPtrs,max_stack);
46  char **symbols=backtrace_symbols(stackPtrs, levels);
47 
48  const int nSkip=2;
49  std::printf( "\nStack Backtrace:\n");
50  for ( int i=nSkip; i<levels; i++) {
51  std::printf( " [%d] %s\n", i-nSkip, symbols[i]);
52  }
53 #endif
54 }
55 
56 std::ostream &operator<<( std::ostream& os, const COM_exception &ex) {
57  os << "Roccom: " << (ex.ierr<1000?"WARNING ":"ERROR ")
58  << ex.ierr << ": ";
59  std::string msg;
60  switch (ex.ierr) {
61  case COM_WARN_DUP_WINDOW:
62  msg = "Duplicated window"; break;
64  msg = "Duplicated attribute"; break;
66  msg = "Duplicated function"; break;
67  case COM_WARN_DUP_FUNC:
68  msg = "Duplicated function"; break;
69  case COM_WARN_EMPTY_MESH:
70  msg = "Empty mesh"; break;
72  msg = "Module has already been loaded"; break;
73 
75  msg = "Module was never loaded"; break;
77  msg = "Could not open library"; break;
79  msg = "Could not find symbol"; break;
80 
82  msg = "Roccom was already initialized"; break;
84  msg = "Roccom was not initialized"; break;
85 
87  msg = "Pane map has changed but input argument claims not"; break;
89  msg = "Window does not exist"; break;
91  msg = "Pane does not exist"; break;
93  msg = "Attribute does not exist"; break;
95  msg = "Function does not exist"; break;
97  msg = "Unknown keyword"; break;
99  msg = "Got an unknown data type"; break;
101  msg = "Invalid attribute name"; break;
102 
104  msg = "Attribute was already intialized"; break;
106  msg = "Attribute was not allocated by Roccom"; break;
108  msg = "A const array cannot be modified, and a non-const reference to it\n\
109  cannot be obtained."; break;
111  msg = "Attribute has already been allocated by Roccom"; break;
113  msg = "Connectivity for structured meshes cannot be Allocated"; break;
115  msg = "Invalid number of components or dimensions"; break;
117  msg = "Invalid size. Cannot be negative or larger than capacity, \n\
118  and the number of ghosts cannot be greater than the total number of items."; break;
120  msg = "Invalid capacity. Cannot be smaller than the registered \n\
121  size or be zero when setting a nonnull array"; break;
123  msg = "Invalid stride. Must be either 1 or >= the number of components"; break;
124  case COM_ERR_INVALID_ADDR:
125  msg = "Invalid address. Probably is trying to register a local/stack variable."; break;
126 
127  case COM_ERR_F90FUNC:
128  msg = "Only F90 functions can accept F90 pointers"; break;
130  msg = "Unknown intention of argument"; break;
131  case COM_ERR_TOO_MANY_ARGS:
132  msg = "Too many arguments"; break;
133  case COM_ERR_TOO_FEW_ARGS:
134  msg = "Too few argument"; break;
136  msg = "Received an invalid function handle"; break;
138  msg = "Received an invalid attribute handle"; break;
140  msg = "Received an invalid window handle"; break;
142  msg = "Incompatible attributes"; break;
144  msg = "Incompatible data types"; break;
145 
147  msg = "Not a window attribute"; break;
149  msg = "Trying to nullify an attribute that is not a pointer"; break;
150  case COM_ERR_IMMUTABLE:
151  msg = "Immutable attributes cannot be passed to mutable arguments"; break;
153  msg = "Unexpected null pointer"; break;
154  case COM_ERR_OUT_OF_MEMORY:
155  msg = "Out of memory"; break;
157  msg = "Index out of bounds"; break;
158 
160  msg = "Parent window does not have all the panes in child window"; break;
162  msg = "Trying to change the meta-data of an inherited attribute"; break;
163  case COM_ERR_RESIZE:
164  msg = "Trying to resize an inherited or user-allocated attribute"; break;
166  msg = "Mesh must be used/cloned before creating any attribute"; break;
168  msg = "Inheritance w/o ghost is not supported for structured meshes"; break;
169  case COM_ERR_MIXED_GHOST:
170  msg = "Ghost elements of unstructured mesh must be at the end"; break;
171  case COM_ERR_GHOST_NODES:
172  msg = "The number of ghost nodes must be <= the total number of nodes"; break;
173  case COM_ERR_GHOST_ELEMS:
174  msg = "The number of ghost elements must be <= the total number of elements"; break;
176  msg = "The number of ghost layers must be <= half of each dimension"; break;
178  msg = "Appending array is supported only for window and pane attributes without ghosts"; break;
179  case COM_UNKNOWN_ERROR:
180  default:
181  msg = "Unknow error";
182  }
183 
184  os << msg << "\nRoccom: Error encountered when processing "
185  << ex.msg << std::endl << "Roccom: ";
186  return os;
187 }
188 
189 std::string
190 append_frame_info( const std::string &s, const char *frame,
191  const char *file, int line) {
192  char buf[1000];
193 
194  std::sprintf( buf, "\nRoccom: In %s of file %s at line %d",
195  frame, file, line);
196  return s+buf;
197 }
198 
199 COM_END_NAME_SPACE
200 
201 
202 
203 
204 
205 
std::string append_frame_info(const std::string &s, const char *frame, const char *file, int line)
Append the information about the given frame to the string s.
double s
Definition: blastest.C:80
Error_code ierr
Error code.
Encapsulates the states of an exception.
std::string msg
Error message.
COM_BEGIN_NAME_SPACE void printStackBacktrace()
Print the stack backtrace.
blockLoc i
Definition: read.cpp:79
std::ostream & operator<<(std::ostream &os, const COM_exception &ex)
Print out a given exception.