1 #ifndef SimTK_SimTKCOMMON_EXCEPTION_H_ 
    2 #define SimTK_SimTKCOMMON_EXCEPTION_H_ 
   42 #pragma warning(disable:4996) 
   46 class 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 {
 
   76         snprintf(buf,n,
"%d",lineNo);
 
   77         return shortenFileName(fileName) + 
":" + std::string(buf);
 
   89     Assert(
const char* fn, 
int ln, 
const char* assertion,
 
   90              const char* fmt ...) : 
Base(fn,ln)
 
   96         vsnprintf(buf, n, fmt, args);
 
   98         setMessage(
"Internal bug detected: " + std::string(buf)
 
   99                    + 
"\n  (Assertion '" + std::string(assertion) + 
"' failed).\n" 
  100             "  Please file an Issue at https://github.com/simbody/simbody/issues.\n" 
  101             "  Include the above information and anything else needed to reproduce the problem.");
 
  118            const char* whereChecked,    
 
  119            const char* fmt ...) : 
Base(fn,ln)
 
  125         vsnprintf(buf, n, fmt, args);
 
  127         setMessage(
"Error detected by Simbody method " 
  128             + std::string(whereChecked) + 
": " 
  130             + 
"\n  (Required condition '" + std::string(assertion) + 
"' was not met.)\n");
 
  146                       const char* className, 
const char* methodName,
 
  147                       const char* fmt ...) : 
Base(fn,ln)
 
  153         vsnprintf(buf, n, fmt, args);
 
  155                    + std::string(className) + 
"::" + std::string(methodName) + 
"(): " 
  157                    + 
"\n  (Required condition '" + std::string(assertion) + 
"' was not met.)");
 
  167                     long long lb, 
long long index, 
long long ub, 
const char* where)
 
  173         snprintf(buf, n, 
"Index out of range in %s: expected %lld <= %s < %lld but %s=%lld.",
 
  174             where,lb,indexName,ub,indexName,index);
 
  183                    unsigned long long sz, 
unsigned long long maxsz, 
const char* where)
 
  189         snprintf(buf, n, 
"Size out of range in %s: expected 0 <= %s <= %llu but %s=%llu.",
 
  190             where,szName,maxsz,szName,sz);
 
  199                    unsigned long long sz, 
const char* where)
 
  205         snprintf(buf, n, 
"Size argument was negative in %s: expected 0 <= %s but %s=%llu.",
 
  206             where,szName,szName,sz);
 
  215                     double lowerBound, 
double value, 
double upperBound,
 
  222         snprintf(buf, n, 
"Value out of range in %s: expected %g <= %s <= %g but %s=%g.",
 
  223             where,lowerBound,valueName,upperBound,valueName,value);
 
  232                      double value, 
const char* where)
 
  238         snprintf(buf, n, 
"Expected non-negative value for %s in %s but got %g.",
 
  239             valueName,where,value);
 
  251             + 
"is not yet implemented. Please post to the Simbody forum" 
  252               " to find a workaround or request implementation.");
 
  260         std::string baseClass, std::string methodName)
 
  264             " dummy implementation of method " + methodName
 
  265             + 
"() was invoked because a derived class did not provide an implementation.");
 
  274         setMessage(
"Attempt to assign a Value<"+src+
"> to a Value<"+dest+
">");
 
  283         setMessage(
"Operation '" + op + 
"' allowed only for owners, not views");
 
  292         setMessage(
"Operation '" + op + 
"' allowed only for views, not owners");
 
  301         setMessage(
"Operation '" + op + 
"' not allowed on non-const readonly view");
 
  309     Cant(
const char* fn, 
int ln, 
const std::string& s) : 
Base(fn,ln)
 
  323 #define SimTK_THROW(exc) \ 
  324     throw exc(__FILE__, __LINE__) 
  325 #define SimTK_THROW1(exc,a1) \ 
  326     throw exc(__FILE__, __LINE__,a1) 
  327 #define SimTK_THROW2(exc,a1,a2) \ 
  328     throw exc(__FILE__, __LINE__,a1,a2) 
  329 #define SimTK_THROW3(exc,a1,a2,a3) \ 
  330     throw exc(__FILE__, __LINE__,a1,a2,a3) 
  331 #define SimTK_THROW4(exc,a1,a2,a3,a4) \ 
  332     throw exc(__FILE__, __LINE__,a1,a2,a3,a4) 
  333 #define SimTK_THROW5(exc,a1,a2,a3,a4,a5) \ 
  334     throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5) 
  335 #define SimTK_THROW6(exc,a1,a2,a3,a4,a5,a6) \ 
  336     throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5,a6) 
  337 #define SimTK_THROW7(exc,a1,a2,a3,a4,a5,a6,a7) \ 
  338     throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5,a6,a7) 
  339 #define SimTK_THROW8(exc,a1,a2,a3,a4,a5,a6,a7,a8) \ 
  340     throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5,a6,a7,a8) 
  341 #define SimTK_THROW9(exc,a1,a2,a3,a4,a5,a6,a7,a8,a9) \ 
  342     throw exc(__FILE__, __LINE__,a1,a2,a3,a4,a5,a6,a7,a8,a9) 
  343 #define SimTK_THROW10(exc,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) \ 
  344     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:143
 
APIArgcheckFailed(const char *fn, int ln, const char *assertion, const char *className, const char *methodName, const char *fmt ...)
Definition: Exception.h:145
 
virtual ~APIArgcheckFailed()
Definition: Exception.h:160
 
This is for reporting internally-detected bugs only, not problems induced by confused users (that is,...
Definition: Exception.h:87
 
virtual ~Assert()
Definition: Exception.h:104
 
Assert(const char *fn, int ln, const char *assertion, const char *fmt ...)
Definition: Exception.h:89
 
Definition: Exception.h:46
 
virtual ~Base()
Definition: Exception.h:50
 
const std::string & getMessage() const
Definition: Exception.h:51
 
Base(const char *fn="<UNKNOWN>", int ln=0)
Definition: Exception.h:48
 
const std::string & getMessageText() const
Definition: Exception.h:52
 
const char * what() const override
Definition: Exception.h:55
 
void setMessage(const std::string &msgin)
Definition: Exception.h:57
 
Definition: Exception.h:307
 
Cant(const char *fn, int ln, const std::string &s)
Definition: Exception.h:309
 
virtual ~Cant()
Definition: Exception.h:313
 
This is for reporting errors occurring during execution of SimTK core methods, beyond those caused by...
Definition: Exception.h:115
 
ErrorCheck(const char *fn, int ln, const char *assertion, const char *whereChecked, const char *fmt ...)
Definition: Exception.h:117
 
virtual ~ErrorCheck()
Definition: Exception.h:133
 
Definition: Exception.h:270
 
IncompatibleValues(const char *fn, int ln, std::string src, std::string dest)
Definition: Exception.h:272
 
virtual ~IncompatibleValues()
Definition: Exception.h:276
 
Definition: Exception.h:164
 
virtual ~IndexOutOfRange()
Definition: Exception.h:177
 
IndexOutOfRange(const char *fn, int ln, const char *indexName, long long lb, long long index, long long ub, const char *where)
Definition: Exception.h:166
 
Definition: Exception.h:297
 
virtual ~OperationNotAllowedOnNonconstReadOnlyView()
Definition: Exception.h:303
 
OperationNotAllowedOnNonconstReadOnlyView(const char *fn, int ln, const std::string &op)
Definition: Exception.h:299
 
Definition: Exception.h:288
 
virtual ~OperationNotAllowedOnOwner()
Definition: Exception.h:294
 
OperationNotAllowedOnOwner(const char *fn, int ln, const std::string &op)
Definition: Exception.h:290
 
Definition: Exception.h:279
 
OperationNotAllowedOnView(const char *fn, int ln, const std::string &op)
Definition: Exception.h:281
 
virtual ~OperationNotAllowedOnView()
Definition: Exception.h:285
 
Definition: Exception.h:180
 
SizeOutOfRange(const char *fn, int ln, const char *szName, unsigned long long sz, unsigned long long maxsz, const char *where)
Definition: Exception.h:182
 
virtual ~SizeOutOfRange()
Definition: Exception.h:193
 
Definition: Exception.h:196
 
virtual ~SizeWasNegative()
Definition: Exception.h:209
 
SizeWasNegative(const char *fn, int ln, const char *szName, unsigned long long sz, const char *where)
Definition: Exception.h:198
 
Definition: Exception.h:245
 
UnimplementedMethod(const char *fn, int ln, std::string methodName)
Definition: Exception.h:247
 
virtual ~UnimplementedMethod()
Definition: Exception.h:254
 
Definition: Exception.h:257
 
UnimplementedVirtualMethod(const char *fn, int ln, std::string baseClass, std::string methodName)
Definition: Exception.h:259
 
virtual ~UnimplementedVirtualMethod()
Definition: Exception.h:267
 
Definition: Exception.h:212
 
virtual ~ValueOutOfRange()
Definition: Exception.h:226
 
ValueOutOfRange(const char *fn, int ln, const char *valueName, double lowerBound, double value, double upperBound, const char *where)
Definition: Exception.h:214
 
Definition: Exception.h:229
 
ValueWasNegative(const char *fn, int ln, const char *valueName, double value, const char *where)
Definition: Exception.h:231
 
virtual ~ValueWasNegative()
Definition: Exception.h:242
 
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37