Go to the documentation of this file.00001
00041 #include "Exception.hh"
00042
00043 #include <stdio.h>
00044 #include <stdarg.h>
00045 #include <stdlib.h>
00046
00047 namespace crl {
00048 namespace multisense {
00049 namespace details {
00050 namespace utility {
00051
00052 #ifndef NEED_VASPRINTF
00053 #define NEED_VASPRINTF 0
00054 #endif
00055
00056 #if NEED_VASPRINTF
00057 int vasprintf (char** strp, const char* fmt, va_list ap)
00058 {
00059 int len = _vscprintf (fmt, ap);
00060 if (len < 0)
00061 {
00062 *strp = NULL;
00063 return len;
00064 }
00065
00066 *strp = (char*)malloc ((size_t)len + 1);
00067 if (*strp == NULL)
00068 {
00069 return -1;
00070 }
00071
00072 len = _vsnprintf (*strp, (size_t)len + 1, fmt, ap);
00073 if (len < 0)
00074 {
00075 free (*strp);
00076 *strp = NULL;
00077 }
00078
00079 return len;
00080 }
00081 #endif
00082
00088 Exception::Exception(const char *failureReason, ...)
00089 {
00090 char *stringP;
00091 va_list ap;
00092 int returnValue;
00093
00094 va_start(ap, failureReason);
00095 returnValue = vasprintf(&stringP, failureReason, ap);
00096 va_end(ap);
00097
00098 if ((NULL != stringP) && (returnValue != -1)) {
00099 reason = std::string(stringP);
00100 free(stringP);
00101 }
00102 }
00103
00104 Exception::Exception(const std::string& failureReason)
00105 {
00106 reason = failureReason;
00107 }
00108
00112 Exception::~Exception() throw()
00113 {
00114
00115 }
00116
00120 const char* Exception::what() const throw()
00121 {
00122 return this->reason.c_str();
00123 }
00124
00125 }}}}