LibMultiSense
LibMultiSense Documentation
Exception.cc
Go to the documentation of this file.
1 
42 #include "utility/Exception.hh"
43 
44 #include <stdio.h>
45 #include <stdarg.h>
46 #include <stdlib.h>
47 
48 namespace crl {
49 namespace multisense {
50 namespace details {
51 namespace utility {
52 
53 #ifndef NEED_VASPRINTF
54 #define NEED_VASPRINTF 0
55 #endif
56 
57 #if NEED_VASPRINTF
58 int vasprintf (char** strp, const char* fmt, va_list ap)
59 {
60  int len = _vscprintf (fmt, ap);
61  if (len < 0)
62  {
63  *strp = NULL;
64  return len;
65  }
66 
67  *strp = (char*)malloc ((size_t)len + 1);
68  if (*strp == NULL)
69  {
70  return -1;
71  }
72 
73  len = _vsnprintf (*strp, (size_t)len + 1, fmt, ap);
74  if (len < 0)
75  {
76  free (*strp);
77  *strp = NULL;
78  }
79 
80  return len;
81 }
82 #endif
83 
89 Exception::Exception(const char *failureReason, ...)
90 {
91  char *stringP;
92  va_list ap;
93  int returnValue;
94 
95  va_start(ap, failureReason);
96  #if defined(__MINGW64__)
97  returnValue = __mingw_vasprintf(&stringP, failureReason, ap);
98  #else
99  returnValue = vasprintf(&stringP, failureReason, ap);
100  #endif
101  va_end(ap);
102 
103  if ((NULL != stringP) && (returnValue != -1)) {
104  reason = std::string(stringP);
105  free(stringP);
106  }
107 }
108 
109 Exception::Exception(const std::string& failureReason)
110 {
111  reason = failureReason;
112 }
113 
118 {
119  // Empty.
120 }
121 
125 const char* Exception::what() const throw()
126 {
127  return this->reason.c_str();
128 }
129 
130 }}}} // namespaces
Exception.hh
crl::multisense::details::utility::Exception::Exception
Exception(const char *failureReason,...)
Constructor.
Definition: Exception.cc:89
crl::multisense::details::utility::Exception::reason
std::string reason
Definition: Exception.hh:112
crl::multisense::details::utility::Exception::~Exception
~Exception()
Destructor.
Definition: Exception.cc:117
crl
Definition: BufferStream.hh:51
crl::multisense::details::utility::Exception::what
virtual const char * what() const
Returns the reason for the exception.
Definition: Exception.cc:125
multisense
Definition: MultiSenseChannel.hh:44