1#ifndef SimTK_SimTKCOMMON_EXCEPTION_H_
2#define SimTK_SimTKCOMMON_EXCEPTION_H_
42#pragma warning(disable:4996)
46class Base :
public std::exception {
48 explicit Base(
const char* fn=
"<UNKNOWN>",
int ln=0)
49 : fileName(fn), lineNo(ln) { }
59 msg =
"SimTK Exception thrown at " + where() +
":\n " + msgin;
67 static std::string shortenFileName(
const std::string& fn)
68 { std::string::size_type pos = fn.find_last_of(
"/\\");
69 if (pos+1>=fn.size()) pos=0;
70 return std::string(fn,(
int)(pos+1),(
int)(fn.size()-(pos+1)));
73 std::string where()
const {
75 sprintf(buf,
"%d",lineNo);
76 return shortenFileName(fileName) +
":" + std::string(buf);
88 Assert(
const char* fn,
int ln,
const char* assertion,
89 const char* fmt ...) :
Base(fn,ln)
94 vsprintf(buf, fmt, args);
96 setMessage(
"Internal bug detected: " + std::string(buf)
97 +
"\n (Assertion '" + std::string(assertion) +
"' failed).\n"
98 " Please file an Issue at https://github.com/simbody/simbody/issues.\n"
99 " Include the above information and anything else needed to reproduce the problem.");
116 const char* whereChecked,
117 const char* fmt ...) :
Base(fn,ln)
122 vsprintf(buf, fmt, args);
124 setMessage(
"Error detected by Simbody method "
125 + std::string(whereChecked) +
": "
127 +
"\n (Required condition '" + std::string(assertion) +
"' was not met.)\n");
143 const char* className,
const char* methodName,
144 const char* fmt ...) :
Base(fn,ln)
149 vsprintf(buf, fmt, args);
151 + std::string(className) +
"::" + std::string(methodName) +
"(): "
153 +
"\n (Required condition '" + std::string(assertion) +
"' was not met.)");
163 long long lb,
long long index,
long long ub,
const char* where)
168 sprintf(buf,
"Index out of range in %s: expected %lld <= %s < %lld but %s=%lld.",
169 where,lb,indexName,ub,indexName,index);
178 unsigned long long sz,
unsigned long long maxsz,
const char* where)
183 sprintf(buf,
"Size out of range in %s: expected 0 <= %s <= %llu but %s=%llu.",
184 where,szName,maxsz,szName,sz);
193 unsigned long long sz,
const char* where)
198 sprintf(buf,
"Size argument was negative in %s: expected 0 <= %s but %s=%llu.",
199 where,szName,szName,sz);
208 double lowerBound,
double value,
double upperBound,
214 sprintf(buf,
"Value out of range in %s: expected %g <= %s <= %g but %s=%g.",
215 where,lowerBound,valueName,upperBound,valueName,value);
224 double value,
const char* where)
229 sprintf(buf,
"Expected non-negative value for %s in %s but got %g.",
230 valueName,where,value);
242 +
"is not yet implemented. Please post to the Simbody forum"
243 " to find a workaround or request implementation.");
251 std::string baseClass, std::string methodName)
255 " dummy implementation of method " + methodName
256 +
"() was invoked because a derived class did not provide an implementation.");
265 setMessage(
"Attempt to assign a Value<"+src+
"> to a Value<"+dest+
">");
274 setMessage(
"Operation '" + op +
"' allowed only for owners, not views");
283 setMessage(
"Operation '" + op +
"' allowed only for views, not owners");
292 setMessage(
"Operation '" + op +
"' not allowed on non-const readonly view");
300 Cant(
const char* fn,
int ln,
const std::string& s) :
Base(fn,ln)
314#define SimTK_THROW(exc) \
315 throw exc(__FILE__, __LINE__)
316#define SimTK_THROW1(exc,a1) \
317 throw exc(__FILE__, __LINE__,a1)
318#define SimTK_THROW2(exc,a1,a2) \
319 throw exc(__FILE__, __LINE__,a1,a2)
320#define SimTK_THROW3(exc,a1,a2,a3) \
321 throw exc(__FILE__, __LINE__,a1,a2,a3)
322#define SimTK_THROW4(exc,a1,a2,a3,a4) \
323 throw exc(__FILE__, __LINE__,a1,a2,a3,a4)
324#define SimTK_THROW5(exc,a1,a2,a3,a4,a5) \
325 throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5)
326#define SimTK_THROW6(exc,a1,a2,a3,a4,a5,a6) \
327 throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5,a6)
328#define SimTK_THROW7(exc,a1,a2,a3,a4,a5,a6,a7) \
329 throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5,a6,a7)
330#define SimTK_THROW8(exc,a1,a2,a3,a4,a5,a6,a7,a8) \
331 throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5,a6,a7,a8)
332#define SimTK_THROW9(exc,a1,a2,a3,a4,a5,a6,a7,a8,a9) \
333 throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5,a6,a7,a8,a9)
334#define SimTK_THROW10(exc,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \
335 throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
Mandatory first inclusion for any Simbody source or header file.
This is for reporting problems detected by checking the caller's supplied arguments to a SimTK API me...
Definition Exception.h:140
APIArgcheckFailed(const char *fn, int ln, const char *assertion, const char *className, const char *methodName, const char *fmt ...)
Definition Exception.h:142
virtual ~APIArgcheckFailed()
Definition Exception.h:156
This is for reporting internally-detected bugs only, not problems induced by confused users (that is,...
Definition Exception.h:86
virtual ~Assert()
Definition Exception.h:102
Assert(const char *fn, int ln, const char *assertion, const char *fmt ...)
Definition Exception.h:88
Definition Exception.h:46
const char * what() const override
Definition Exception.h:55
virtual ~Base()
Definition Exception.h:50
Base(const char *fn="<UNKNOWN>", int ln=0)
Definition Exception.h:48
const std::string & getMessageText() const
Definition Exception.h:52
void setMessage(const std::string &msgin)
Definition Exception.h:57
const std::string & getMessage() const
Definition Exception.h:51
Definition Exception.h:298
Cant(const char *fn, int ln, const std::string &s)
Definition Exception.h:300
virtual ~Cant()
Definition Exception.h:304
This is for reporting errors occurring during execution of SimTK core methods, beyond those caused by...
Definition Exception.h:113
ErrorCheck(const char *fn, int ln, const char *assertion, const char *whereChecked, const char *fmt ...)
Definition Exception.h:115
virtual ~ErrorCheck()
Definition Exception.h:130
Definition Exception.h:261
IncompatibleValues(const char *fn, int ln, std::string src, std::string dest)
Definition Exception.h:263
virtual ~IncompatibleValues()
Definition Exception.h:267
Definition Exception.h:160
virtual ~IndexOutOfRange()
Definition Exception.h:172
IndexOutOfRange(const char *fn, int ln, const char *indexName, long long lb, long long index, long long ub, const char *where)
Definition Exception.h:162
Definition Exception.h:288
virtual ~OperationNotAllowedOnNonconstReadOnlyView()
Definition Exception.h:294
OperationNotAllowedOnNonconstReadOnlyView(const char *fn, int ln, const std::string &op)
Definition Exception.h:290
Definition Exception.h:279
virtual ~OperationNotAllowedOnOwner()
Definition Exception.h:285
OperationNotAllowedOnOwner(const char *fn, int ln, const std::string &op)
Definition Exception.h:281
Definition Exception.h:270
OperationNotAllowedOnView(const char *fn, int ln, const std::string &op)
Definition Exception.h:272
virtual ~OperationNotAllowedOnView()
Definition Exception.h:276
Definition Exception.h:175
SizeOutOfRange(const char *fn, int ln, const char *szName, unsigned long long sz, unsigned long long maxsz, const char *where)
Definition Exception.h:177
virtual ~SizeOutOfRange()
Definition Exception.h:187
Definition Exception.h:190
virtual ~SizeWasNegative()
Definition Exception.h:202
SizeWasNegative(const char *fn, int ln, const char *szName, unsigned long long sz, const char *where)
Definition Exception.h:192
Definition Exception.h:236
UnimplementedMethod(const char *fn, int ln, std::string methodName)
Definition Exception.h:238
virtual ~UnimplementedMethod()
Definition Exception.h:245
Definition Exception.h:248
UnimplementedVirtualMethod(const char *fn, int ln, std::string baseClass, std::string methodName)
Definition Exception.h:250
virtual ~UnimplementedVirtualMethod()
Definition Exception.h:258
Definition Exception.h:205
virtual ~ValueOutOfRange()
Definition Exception.h:218
ValueOutOfRange(const char *fn, int ln, const char *valueName, double lowerBound, double value, double upperBound, const char *where)
Definition Exception.h:207
Definition Exception.h:221
ValueWasNegative(const char *fn, int ln, const char *valueName, double value, const char *where)
Definition Exception.h:223
virtual ~ValueWasNegative()
Definition Exception.h:233
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition Assembler.h:37