CPN
Computational Process Networks
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
ErrnoException Class Reference

#include <ErrnoException.h>

+ Inheritance diagram for ErrnoException:
+ Collaboration diagram for ErrnoException:

Public Member Functions

 ErrnoException () throw ()
 
 ErrnoException (int err) throw ()
 
 ErrnoException (const char *msg, int err) throw ()
 
virtual ~ErrnoException () throw ()
 
virtual const char * what () const throw ()
 
int Error () const
 
std::string GetStackTrace () const
 

Protected Attributes

std::string stacktrace
 

Private Member Functions

void Fill () throw ()
 

Private Attributes

int error
 
std::string errorstring
 

Detailed Description

A generic exception that encapsulates the errno value.

Note that this dynamically allocates memory so is unsutable for out of memory errors.

Definition at line 37 of file ErrnoException.h.

Constructor & Destructor Documentation

ErrnoException::ErrnoException ( )
throw (
)

Definition at line 31 of file ErrnoException.cc.

References errorstring, Fill(), and Exception::GetStackTrace().

32  : Exception(3), error(errno)
33 {
34  Fill();
35  errorstring += "\nBacktrace:\n" + GetStackTrace();
36 }
std::string errorstring
Exception(int ignore=2)
Definition: Exception.cc:27
std::string GetStackTrace() const
Definition: Exception.h:40

+ Here is the call graph for this function:

ErrnoException::ErrnoException ( int  err)
throw (
)

Definition at line 38 of file ErrnoException.cc.

39  : Exception(3), error(err)
40 {
41  Fill();
42  errorstring += "\nBacktrace:\n" + GetStackTrace();
43 }
std::string errorstring
Exception(int ignore=2)
Definition: Exception.cc:27
std::string GetStackTrace() const
Definition: Exception.h:40
ErrnoException::ErrnoException ( const char *  msg,
int  err 
)
throw (
)

Definition at line 45 of file ErrnoException.cc.

46  : Exception(3), error(err)
47 {
48  Fill();
49  errorstring += ": ";
50  errorstring += msg;
51  errorstring += "\nBacktrace:\n" + GetStackTrace();
52 }
std::string errorstring
Exception(int ignore=2)
Definition: Exception.cc:27
std::string GetStackTrace() const
Definition: Exception.h:40
ErrnoException::~ErrnoException ( )
throw (
)
virtual

Definition at line 54 of file ErrnoException.cc.

54  {
55 }

Member Function Documentation

int ErrnoException::Error ( void  ) const
inline
void ErrnoException::Fill ( )
throw (
)
private

Definition at line 61 of file ErrnoException.cc.

References error, errorstring, and UNKNOWN_ERROR.

Referenced by ErrnoException().

61  {
62  std::vector<char> errstr(256, '\0');
63  do {
64 #if defined(__APPLE__)
65  // if __APPLE__ strerror_r is declared to return an int
66  int err = strerror_r(error, &errstr[0], errstr.size());
67  if (err == 0) {
68  errorstring = &errstr[0];
69  break;
70  } else {
71  if (errno == ERANGE) {
72  errstr.resize(2*errstr.size(), '\0');
73  } else {
75  break;
76  }
77  }
78 #else
79  char *str = strerror_r(error, &errstr[0], errstr.size());
80 
81  // Wierdness with different versions of strerror... From the man page:
82  //
83  // The strerror() and strerror_r() functions return the appropriate
84  // error description string, or an "Unknown error nnn" message if the
85  // error number is unknown.
86  //
87  // The XSI-compliant strerror_r() function returns 0 on success; on
88  // error, -1 is returned and errno is set to indicate the error.
89  //
90  // So str can be ether an error code OR a pointer to the error
91  // string... wierdness.
92 
93  if (str == (char*)-1) {
94  if (errno == ERANGE) {
95  errstr.resize(2*errstr.size(), '\0');
96  } else {
98  break;
99  }
100  } else if (str == 0) {
101  errorstring = &errstr[0];
102  break;
103  } else {
104  errorstring = str;
105  break;
106  }
107 #endif
108  } while (true);
109 }
std::string errorstring
static const char UNKNOWN_ERROR[]

+ Here is the caller graph for this function:

std::string Exception::GetStackTrace ( ) const
inlineinherited
Returns
the stack trace.

Definition at line 40 of file Exception.h.

References Exception::stacktrace.

Referenced by ErrnoException().

40 { return stacktrace; }
std::string stacktrace
Definition: Exception.h:42

+ Here is the caller graph for this function:

const char * ErrnoException::what ( ) const
throw (
)
virtual

Member Data Documentation

int ErrnoException::error
private

Definition at line 47 of file ErrnoException.h.

Referenced by Error(), and Fill().

std::string ErrnoException::errorstring
private

Definition at line 48 of file ErrnoException.h.

Referenced by ErrnoException(), Fill(), and what().

std::string Exception::stacktrace
protectedinherited

Definition at line 42 of file Exception.h.

Referenced by Exception::GetStackTrace().


The documentation for this class was generated from the following files: