LibMultiSense
LibMultiSense Documentation
Loading...
Searching...
No Matches
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
48namespace crl {
49namespace multisense {
50namespace details {
51namespace utility {
52
53#ifndef NEED_VASPRINTF
54#define NEED_VASPRINTF 0
55#endif
56
57#if NEED_VASPRINTF
58int 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
89Exception::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
109Exception::Exception(const std::string& failureReason)
110{
111 reason = failureReason;
112}
113
118{
119 // Empty.
120}
121
125const char* Exception::what() const throw()
126{
127 return this->reason.c_str();
128}
129
130}}}} // namespaces
This header file is adapted from Eric Kratzer's (and Dan Tascione's?) StandardException....
Exception(const char *failureReason,...)
Constructor.
Definition Exception.cc:89
virtual const char * what() const
Returns the reason for the exception.
Definition Exception.cc:125