This is Unofficial EPICS BASE Doxygen Site
epicsException.cpp
Go to the documentation of this file.
1 /*
2  * Copyright information and license terms for this software can be
3  * found in the file LICENSE that is included with the distribution
4  */
9 #include <sstream>
10 #include <cstdio>
11 #include <cstring>
12 #include <cstdlib>
13 #include <string>
14 
15 #define epicsExportSharedSymbols
16 #include <pv/epicsException.h>
17 
18 using std::string;
19 
20 namespace epics{ namespace pvData {
21 
22 void
23 ExceptionMixin::print(FILE *fp) const
24 {
25  fprintf(fp, "On line %d of %s\n",m_line,m_file);
26 
27 #if defined(EXCEPT_USE_BACKTRACE)
28  if(m_depth>0) {
29  fflush(fp); // must flush before using raw handle
30  backtrace_symbols_fd(m_stack, m_depth, fileno(fp));
31  fprintf(fp, "To translate run 'addr2line -e execname 0xXXXXXXX ...'\n"
32  " Note: Must be compiled with debug symbols\n");
33  }
34 #endif
35 }
36 
37 string
39 {
40  std::ostringstream out;
41 
42  out<<"On line "<<m_line<<" of "<<m_file<<"\n";
43 
44 #if defined(EXCEPT_USE_BACKTRACE)
45  if (m_depth>0) {
46 
47  char **symbols=backtrace_symbols(m_stack, m_depth);
48 
49  for(int i=0; i<m_depth; i++) {
50  out<<symbols[i]<<"\n";
51  }
52 
53  std::free(symbols);
54  }
55 
56 #endif
57  return out.str();
58 }
59 
60 
61 const char*
62 BaseException::what() const throw()
63 {
64  try{
65  if (base_msg.size()==0) {
66  const char *base=std::logic_error::what();
67  string out, stack;
68 
69  const ExceptionMixin *info=dynamic_cast<const ExceptionMixin*>(this);
70  if(info) {
71  stack=info->show();
72  }
73 
74  out.reserve(strlen(base)+1+stack.size()+1);
75 
76  out+=base;
77  out+="\n";
78  if(info) {
79  out+=stack;
80  out+="\n";
81  }
82 
83  base_msg.swap(out);
84  }
85  return base_msg.c_str();
86  } catch(std::bad_alloc&) {
87  return "BaseException::what - Insufficient memory to construct message";
88  } catch(...) {
89  return "BaseException::what - Unknown error when constructing message";
90  }
91 }
92 
93 }}
int i
Definition: scan.c:967
void print(FILE *fp=stderr) const
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
virtual const char * what() const
int * base
Definition: flex.c:92