1 #ifndef SimTK_SimTKCOMMON_EXCEPTION_H_ 2 #define SimTK_SimTKCOMMON_EXCEPTION_H_ 29 #pragma warning(disable:4996) 45 class Base :
public std::exception {
47 explicit Base(
const char* fn=
"<UNKNOWN>",
int ln=0)
48 : fileName(fn), lineNo(ln) { }
58 msg =
"SimTK Exception thrown at " + where() +
":\n " + msgin;
66 static std::string shortenFileName(
const std::string& fn)
67 { std::string::size_type pos = fn.find_last_of(
"/\\");
68 if (pos+1>=fn.size()) pos=0;
69 return std::string(fn,(
int)(pos+1),(
int)(fn.size()-(pos+1)));
72 std::string where()
const {
74 sprintf(buf,
"%d",lineNo);
75 return shortenFileName(fileName) +
":" + std::string(buf);
87 Assert(
const char* fn,
int ln,
const char* assertion,
88 const char* fmt ...) :
Base(fn,ln)
93 vsprintf(buf, fmt, args);
95 setMessage(
"Internal bug detected: " + std::string(buf)
96 +
"\n (Assertion '" + std::string(assertion) +
"' failed).\n" 97 " Please file an Issue at https://github.com/simbody/simbody/issues.\n" 98 " Include the above information and anything else needed to reproduce the problem.");
115 const char* whereChecked,
116 const char* fmt ...) :
Base(fn,ln)
121 vsprintf(buf, fmt, args);
123 setMessage(
"Error detected by Simbody method " 124 + std::string(whereChecked) +
": " 126 +
"\n (Required condition '" + std::string(assertion) +
"' was not met.)\n");
142 const char* className,
const char* methodName,
143 const char* fmt ...) :
Base(fn,ln)
148 vsprintf(buf, fmt, args);
150 + std::string(className) +
"::" + std::string(methodName) +
"(): " 152 +
"\n (Required condition '" + std::string(assertion) +
"' was not met.)");
162 long long lb,
long long index,
long long ub,
const char* where)
167 sprintf(buf,
"Index out of range in %s: expected %lld <= %s < %lld but %s=%lld.",
168 where,lb,indexName,ub,indexName,index);
177 unsigned long long sz,
unsigned long long maxsz,
const char* where)
182 sprintf(buf,
"Size out of range in %s: expected 0 <= %s <= %llu but %s=%llu.",
183 where,szName,maxsz,szName,sz);
192 unsigned long long sz,
const char* where)
197 sprintf(buf,
"Size argument was negative in %s: expected 0 <= %s but %s=%llu.",
198 where,szName,szName,sz);
207 double lowerBound,
double value,
double upperBound,
213 sprintf(buf,
"Value out of range in %s: expected %g <= %s <= %g but %s=%g.",
214 where,lowerBound,valueName,upperBound,valueName,value);
223 double value,
const char* where)
228 sprintf(buf,
"Expected non-negative value for %s in %s but got %g.",
229 valueName,where,value);
241 +
"is not yet implemented. Please post to the Simbody forum" 242 " to find a workaround or request implementation.");
250 std::string baseClass, std::string methodName)
254 " dummy implementation of method " + methodName
255 +
"() was invoked because a derived class did not provide an implementation.");
264 setMessage(
"Attempt to assign a Value<"+src+
"> to a Value<"+dest+
">");
273 setMessage(
"Operation '" + op +
"' allowed only for owners, not views");
282 setMessage(
"Operation '" + op +
"' allowed only for views, not owners");
291 setMessage(
"Operation '" + op +
"' not allowed on non-const readonly view");
299 Cant(
const char* fn,
int ln,
const std::string& s) :
Base(fn,ln)
309 #define SimTK_THROW(exc) \ 310 throw exc(__FILE__, __LINE__) 311 #define SimTK_THROW1(exc,a1) \ 312 throw exc(__FILE__, __LINE__,a1) 313 #define SimTK_THROW2(exc,a1,a2) \ 314 throw exc(__FILE__, __LINE__,a1,a2) 315 #define SimTK_THROW3(exc,a1,a2,a3) \ 316 throw exc(__FILE__, __LINE__,a1,a2,a3) 317 #define SimTK_THROW4(exc,a1,a2,a3,a4) \ 318 throw exc(__FILE__, __LINE__,a1,a2,a3,a4) 319 #define SimTK_THROW5(exc,a1,a2,a3,a4,a5) \ 320 throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5) 321 #define SimTK_THROW6(exc,a1,a2,a3,a4,a5,a6) \ 322 throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5,a6) 323 #define SimTK_THROW7(exc,a1,a2,a3,a4,a5,a6,a7) \ 324 throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5,a6,a7) 325 #define SimTK_THROW8(exc,a1,a2,a3,a4,a5,a6,a7,a8) \ 326 throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5,a6,a7,a8) 327 #define SimTK_THROW9(exc,a1,a2,a3,a4,a5,a6,a7,a8,a9) \ 328 throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5,a6,a7,a8,a9) 329 #define SimTK_THROW10(exc,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \ 330 throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) 332 #endif // SimTK_SimTKCOMMON_EXCEPTION_H_ virtual ~UnimplementedMethod()
Definition: Exception.h:244
ValueOutOfRange(const char *fn, int ln, const char *valueName, double lowerBound, double value, double upperBound, const char *where)
Definition: Exception.h:206
Definition: Exception.h:204
virtual ~Assert()
Definition: Exception.h:101
const char * what() const
Definition: Exception.h:54
const std::string & getMessage() const
Definition: Exception.h:50
SizeOutOfRange(const char *fn, int ln, const char *szName, unsigned long long sz, unsigned long long maxsz, const char *where)
Definition: Exception.h:176
Definition: Exception.h:287
Base(const char *fn="<UNKNOWN>", int ln=0)
Definition: Exception.h:47
virtual ~Base()
Definition: Exception.h:49
void setMessage(const std::string &msgin)
Definition: Exception.h:56
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
This is for reporting internally-detected bugs only, not problems induced by confused users (that is...
Definition: Exception.h:85
virtual ~IndexOutOfRange()
Definition: Exception.h:171
OperationNotAllowedOnNonconstReadOnlyView(const char *fn, int ln, const std::string &op)
Definition: Exception.h:289
SizeWasNegative(const char *fn, int ln, const char *szName, unsigned long long sz, const char *where)
Definition: Exception.h:191
Definition: Exception.h:297
virtual ~ErrorCheck()
Definition: Exception.h:129
const std::string & getMessageText() const
Definition: Exception.h:51
ErrorCheck(const char *fn, int ln, const char *assertion, const char *whereChecked, const char *fmt...)
Definition: Exception.h:114
Definition: Exception.h:174
Definition: Exception.h:189
Definition: Exception.h:278
UnimplementedMethod(const char *fn, int ln, std::string methodName)
Definition: Exception.h:237
virtual ~OperationNotAllowedOnView()
Definition: Exception.h:275
virtual ~SizeWasNegative()
Definition: Exception.h:201
virtual ~SizeOutOfRange()
Definition: Exception.h:186
This is for reporting errors occurring during execution of SimTK core methods, beyond those caused by...
Definition: Exception.h:112
virtual ~Cant()
Definition: Exception.h:303
Definition: Exception.h:45
Definition: Exception.h:159
Assert(const char *fn, int ln, const char *assertion, const char *fmt...)
Definition: Exception.h:87
Definition: Exception.h:260
UnimplementedVirtualMethod(const char *fn, int ln, std::string baseClass, std::string methodName)
Definition: Exception.h:249
virtual ~UnimplementedVirtualMethod()
Definition: Exception.h:257
virtual ~OperationNotAllowedOnNonconstReadOnlyView()
Definition: Exception.h:293
IncompatibleValues(const char *fn, int ln, std::string src, std::string dest)
Definition: Exception.h:262
virtual ~APIArgcheckFailed()
Definition: Exception.h:155
Definition: Exception.h:220
This is for reporting problems detected by checking the caller's supplied arguments to a SimTK API me...
Definition: Exception.h:139
OperationNotAllowedOnOwner(const char *fn, int ln, const std::string &op)
Definition: Exception.h:280
ValueWasNegative(const char *fn, int ln, const char *valueName, double value, const char *where)
Definition: Exception.h:222
virtual ~ValueOutOfRange()
Definition: Exception.h:217
Mandatory first inclusion for any Simbody source or header file.
Definition: Exception.h:235
Definition: Exception.h:247
IndexOutOfRange(const char *fn, int ln, const char *indexName, long long lb, long long index, long long ub, const char *where)
Definition: Exception.h:161
Cant(const char *fn, int ln, const std::string &s)
Definition: Exception.h:299
APIArgcheckFailed(const char *fn, int ln, const char *assertion, const char *className, const char *methodName, const char *fmt...)
Definition: Exception.h:141
virtual ~IncompatibleValues()
Definition: Exception.h:266
Definition: Exception.h:269
virtual ~OperationNotAllowedOnOwner()
Definition: Exception.h:284
OperationNotAllowedOnView(const char *fn, int ln, const std::string &op)
Definition: Exception.h:271
virtual ~ValueWasNegative()
Definition: Exception.h:232