Exception.cc
Go to the documentation of this file.
1 
41 #include "Exception.hh"
42 
43 #include <stdio.h>
44 #include <stdarg.h>
45 #include <stdlib.h>
46 
47 namespace crl {
48 namespace multisense {
49 namespace details {
50 namespace utility {
51 
52 #ifndef NEED_VASPRINTF
53 #define NEED_VASPRINTF 0
54 #endif
55 
56 #if NEED_VASPRINTF
57 int vasprintf (char** strp, const char* fmt, va_list ap)
58 {
59  int len = _vscprintf (fmt, ap);
60  if (len < 0)
61  {
62  *strp = NULL;
63  return len;
64  }
65 
66  *strp = (char*)malloc ((size_t)len + 1);
67  if (*strp == NULL)
68  {
69  return -1;
70  }
71 
72  len = _vsnprintf (*strp, (size_t)len + 1, fmt, ap);
73  if (len < 0)
74  {
75  free (*strp);
76  *strp = NULL;
77  }
78 
79  return len;
80 }
81 #endif
82 
88 Exception::Exception(const char *failureReason, ...)
89 {
90  char *stringP;
91  va_list ap;
92  int returnValue;
93 
94  va_start(ap, failureReason);
95  returnValue = vasprintf(&stringP, failureReason, ap);
96  va_end(ap);
97 
98  if ((NULL != stringP) && (returnValue != -1)) {
99  reason = std::string(stringP);
100  free(stringP);
101  }
102 }
103 
104 Exception::Exception(const std::string& failureReason)
105 {
106  reason = failureReason;
107 }
108 
113 {
114  // Empty.
115 }
116 
120 const char* Exception::what() const throw()
121 {
122  return this->reason.c_str();
123 }
124 
125 }}}} // namespaces
Definition: channel.cc:56
Exception(const char *failureReason,...)
Definition: Exception.cc:88
virtual const char * what() const
Definition: Exception.cc:120


multisense_lib
Author(s):
autogenerated on Sat Apr 6 2019 02:16:46