Go to the documentation of this file. 1 #ifndef SimTK_SimTKCOMMON_EXCEPTION_MACROS_H_
2 #define SimTK_SimTKCOMMON_EXCEPTION_MACROS_H_
106 #define SimTK_INDEXCHECK_ALWAYS(ix,ub,where) \
107 do{if(!isIndexInRange((ix),(ub)))SimTK_THROW5(SimTK::Exception::IndexOutOfRange, \
108 #ix,0,(ix),(ub),(where));}while(false)
114 #define SimTK_SIZECHECK_ALWAYS(sz,maxsz,where) \
115 do{if(!isSizeInRange((sz),(maxsz)))SimTK_THROW4(SimTK::Exception::SizeOutOfRange, \
116 #sz,(sz),(maxsz),(where));}while(false)
121 #define SimTK_SIZECHECK_NONNEG_ALWAYS(sz,where) \
122 do{if(!isNonnegative(sz))SimTK_THROW3(SimTK::Exception::SizeWasNegative, \
123 #sz,(sz),(where));}while(false)
127 #define SimTK_VALUECHECK_ALWAYS(lb,val,ub,valName,where) \
128 do{if(!((lb)<=(val)&&(val)<=(ub)))SimTK_THROW5(SimTK::Exception::ValueOutOfRange, \
129 (valName),(lb),(val),(ub),(where));}while(false)
132 #define SimTK_VALUECHECK_NONNEG_ALWAYS(val,valName,where) \
133 do{if((val)<0)SimTK_THROW3(SimTK::Exception::ValueWasNegative, \
134 (valName),(val),(where));}while(false)
138 #if defined(NDEBUG) && !defined(SimTK_KEEP_RANGECHECK)
139 #define SimTK_INDEXCHECK(ix,ub,where)
140 #define SimTK_SIZECHECK(sz,maxsz,where)
141 #define SimTK_SIZECHECK_NONNEG(sz,where)
142 #define SimTK_VALUECHECK(lb,val,ub,valName,where)
143 #define SimTK_VALUECHECK_NONNEG(val,valName,where)
145 #define SimTK_INDEXCHECK(ix,ub,where) SimTK_INDEXCHECK_ALWAYS(ix,ub,where)
146 #define SimTK_SIZECHECK(sz,maxsz,where) SimTK_SIZECHECK_ALWAYS(sz,maxsz,where)
147 #define SimTK_SIZECHECK_NONNEG(sz,where) SimTK_SIZECHECK_NONNEG_ALWAYS(sz,where)
148 #define SimTK_VALUECHECK(lb,val,ub,valName,where) SimTK_VALUECHECK_ALWAYS(lb,val,ub,valName,where)
149 #define SimTK_VALUECHECK_NONNEG(val,valName,where) SimTK_VALUECHECK_NONNEG_ALWAYS(val,valName,where)
167 #define SimTK_STAGECHECK_TOPOLOGY_REALIZED_ALWAYS(cond,objType,objName,methodNm) \
168 do{if(!(cond)) SimTK_THROW3(SimTK::Exception::RealizeTopologyMustBeCalledFirst, \
169 (objType),(objName),(methodNm));}while(false)
170 #define SimTK_STAGECHECK_TOPOLOGY_VERSION_ALWAYS(sysTopoVersion, \
171 stateTopoVersion,objType,objName,methodNm) \
172 do{if((stateTopoVersion)!=(sysTopoVersion)) \
173 SimTK_THROW5(SimTK::Exception::StateAndSystemTopologyVersionsMustMatch, \
174 (objType),(objName),(methodNm), \
175 (int)(sysTopoVersion),(int)(stateTopoVersion));} \
177 #define SimTK_STAGECHECK_EQ_ALWAYS(currentStage,targetStage,methodNm) \
178 do{if((currentStage)!=(targetStage)) SimTK_THROW3(SimTK::Exception::StageIsWrong, \
179 (currentStage),(targetStage),(methodNm));}while(false)
180 #define SimTK_STAGECHECK_GE_ALWAYS(currentStage,targetStage,methodNm) \
181 do{if(!((currentStage)>=(targetStage))) SimTK_THROW3(SimTK::Exception::StageTooLow, \
182 (currentStage),(targetStage),(methodNm));}while(false)
183 #define SimTK_STAGECHECK_LT_ALWAYS(currentStage,targetStage,methodNm) \
184 do{if((currentStage)>=(targetStage)) SimTK_THROW3(SimTK::Exception::StageTooHigh, \
185 (currentStage),(targetStage),(methodNm));}while(false)
186 #define SimTK_STAGECHECK_RANGE_ALWAYS(lower,current,upper,methodNm) \
187 do{if(!((lower)<=(current)&&(current)<=(upper))) SimTK_THROW4(SimTK::Exception::StageOutOfRange, \
188 (lower),(current),(upper),(methodNm));}while(false)
191 #if defined(NDEBUG) && !defined(SimTK_KEEP_STAGECHECK)
192 #define SimTK_STAGECHECK_TOPOLOGY_REALIZED(cond,objType,objName,methodName)
193 #define SimTK_STAGECHECK_TOPOLOGY_VERSIONS(sysTopoVersion,stateTopoVersion,\
194 objType,objName,methodNm)
195 #define SimTK_STAGECHECK_EQ(currentStage,targetStage,methodNm)
196 #define SimTK_STAGECHECK_GE(currentStage,targetStage,methodNm)
197 #define SimTK_STAGECHECK_LT(currentStage,targetStage,methodNm)
198 #define SimTK_STAGECHECK_RANGE(lower,current,upper,methodNm)
200 #define SimTK_STAGECHECK_TOPOLOGY_REALIZED(cond,objType,objName,methodName) \
201 SimTK_STAGECHECK_TOPOLOGY_REALIZED_ALWAYS(cond,objType,objName,methodName)
202 #define SimTK_STAGECHECK_TOPOLOGY_VERSION(sysTopoVersion,stateTopoVersion, \
203 objType,objName,methodNm) \
204 SimTK_STAGECHECK_TOPOLOGY_VERSION_ALWAYS(sysTopoVersion,stateTopoVersion,\
205 objType,objName,methodNm)
206 #define SimTK_STAGECHECK_EQ(currentStage,targetStage,methodNm) \
207 SimTK_STAGECHECK_EQ_ALWAYS(currentStage,targetStage,methodNm)
208 #define SimTK_STAGECHECK_GE(currentStage,targetStage,methodNm) \
209 SimTK_STAGECHECK_GE_ALWAYS(currentStage,targetStage,methodNm)
210 #define SimTK_STAGECHECK_LT(currentStage,targetStage,methodNm) \
211 SimTK_STAGECHECK_LE_ALWAYS(currentStage,targetStage,methodNm)
212 #define SimTK_STAGECHECK_RANGE(lower,current,upper,methodNm) \
213 SimTK_STAGECHECK_RANGE_ALWAYS(lower,current,upper,methodNm)
224 #define SimTK_APIARGCHECK_ALWAYS(cond,className,methodName,msg) \
225 do{if(!(cond))SimTK_THROW4(SimTK::Exception::APIArgcheckFailed, \
226 #cond,(className),(methodName),(msg)); \
228 #define SimTK_APIARGCHECK1_ALWAYS(cond,className,methodName,fmt,a1) \
229 do{if(!(cond))SimTK_THROW5(SimTK::Exception::APIArgcheckFailed, \
230 #cond,(className),(methodName),(fmt),(a1)); \
232 #define SimTK_APIARGCHECK2_ALWAYS(cond,className,methodName,fmt,a1,a2) \
233 do{if(!(cond))SimTK_THROW6(SimTK::Exception::APIArgcheckFailed, \
234 #cond,(className),(methodName),(fmt),(a1),(a2)); \
236 #define SimTK_APIARGCHECK3_ALWAYS(cond,className,methodName,fmt,a1,a2,a3) \
237 do{if(!(cond))SimTK_THROW7(SimTK::Exception::APIArgcheckFailed, \
238 #cond,(className),(methodName),(fmt),(a1),(a2),(a3)); \
240 #define SimTK_APIARGCHECK4_ALWAYS(cond,className,methodName,fmt,a1,a2,a3,a4) \
241 do{if(!(cond))SimTK_THROW8(SimTK::Exception::APIArgcheckFailed, \
242 #cond,(className),(methodName),(fmt),(a1),(a2),(a3),(a4)); \
244 #define SimTK_APIARGCHECK5_ALWAYS(cond,className,methodName,fmt,a1,a2,a3,a4,a5) \
245 do{if(!(cond))SimTK_THROW9(SimTK::Exception::APIArgcheckFailed, \
246 #cond,(className),(methodName),(fmt),(a1),(a2),(a3),(a4),(a5)); \
249 #if defined(NDEBUG) && !defined(SimTK_KEEP_APIARGCHECK)
250 #define SimTK_APIARGCHECK(cond,className,methodName,msg)
251 #define SimTK_APIARGCHECK1(cond,className,methodName,fmt,a1)
252 #define SimTK_APIARGCHECK2(cond,className,methodName,fmt,a1,a2)
253 #define SimTK_APIARGCHECK3(cond,className,methodName,fmt,a1,a2,a3)
254 #define SimTK_APIARGCHECK4(cond,className,methodName,fmt,a1,a2,a3,a4)
255 #define SimTK_APIARGCHECK5(cond,className,methodName,fmt,a1,a2,a3,a4,a5)
257 #define SimTK_APIARGCHECK(cond,className,methodName,msg) \
258 SimTK_APIARGCHECK_ALWAYS(cond,className,methodName,msg)
259 #define SimTK_APIARGCHECK1(cond,className,methodName,fmt,a1) \
260 SimTK_APIARGCHECK1_ALWAYS(cond,className,methodName,fmt,a1)
261 #define SimTK_APIARGCHECK2(cond,className,methodName,fmt,a1,a2) \
262 SimTK_APIARGCHECK2_ALWAYS(cond,className,methodName,fmt,a1,a2)
263 #define SimTK_APIARGCHECK3(cond,className,methodName,fmt,a1,a2,a3) \
264 SimTK_APIARGCHECK3_ALWAYS(cond,className,methodName,fmt,a1,a2,a3)
265 #define SimTK_APIARGCHECK4(cond,className,methodName,fmt,a1,a2,a3,a4) \
266 SimTK_APIARGCHECK4_ALWAYS(cond,className,methodName,fmt,a1,a2,a3,a4)
267 #define SimTK_APIARGCHECK5(cond,className,methodName,fmt,a1,a2,a3,a4,a5) \
268 SimTK_APIARGCHECK5_ALWAYS(cond,className,methodName,fmt,a1,a2,a3,a4,a5)
281 #define SimTK_ERRCHK_ALWAYS(cond,whereChecked,msg) \
282 do{if(!(cond))SimTK_THROW3(SimTK::Exception::ErrorCheck, \
283 #cond,(whereChecked),(msg)); \
285 #define SimTK_ERRCHK1_ALWAYS(cond,whereChecked,fmt,a1) \
286 do{if(!(cond))SimTK_THROW4(SimTK::Exception::ErrorCheck, \
287 #cond,(whereChecked),(fmt),(a1)); \
289 #define SimTK_ERRCHK2_ALWAYS(cond,whereChecked,fmt,a1,a2) \
290 do{if(!(cond))SimTK_THROW5(SimTK::Exception::ErrorCheck, \
291 #cond,(whereChecked),(fmt),(a1),(a2)); \
293 #define SimTK_ERRCHK3_ALWAYS(cond,whereChecked,fmt,a1,a2,a3) \
294 do{if(!(cond))SimTK_THROW6(SimTK::Exception::ErrorCheck, \
295 #cond,(whereChecked),(fmt),(a1),(a2),(a3)); \
297 #define SimTK_ERRCHK4_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4) \
298 do{if(!(cond))SimTK_THROW7(SimTK::Exception::ErrorCheck, \
299 #cond,(whereChecked),(fmt),(a1),(a2),(a3),(a4)); \
301 #define SimTK_ERRCHK5_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4,a5) \
302 do{if(!(cond))SimTK_THROW8(SimTK::Exception::ErrorCheck, \
303 #cond,(whereChecked),(fmt),(a1),(a2),(a3),(a4),(a5)); \
305 #define SimTK_ERRCHK6_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6) \
306 do{if(!(cond))SimTK_THROW9(SimTK::Exception::ErrorCheck, \
307 #cond,(whereChecked),(fmt),(a1),(a2),(a3),(a4),(a5),(a6)); \
309 #define SimTK_ERRCHK7_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6,a7) \
310 do{if(!(cond))SimTK_THROW10(SimTK::Exception::ErrorCheck, \
311 #cond,(whereChecked),(fmt),(a1),(a2),(a3),(a4),(a5),(a6),(a7)); \
314 #if defined(NDEBUG) && !defined(SimTK_KEEP_ERRCHK)
315 #define SimTK_ERRCHK(cond,whereChecked,msg)
316 #define SimTK_ERRCHK1(cond,whereChecked,fmt,a1)
317 #define SimTK_ERRCHK2(cond,whereChecked,fmt,a1,a2)
318 #define SimTK_ERRCHK3(cond,whereChecked,fmt,a1,a2,a3)
319 #define SimTK_ERRCHK4(cond,whereChecked,fmt,a1,a2,a3,a4)
320 #define SimTK_ERRCHK5(cond,whereChecked,fmt,a1,a2,a3,a4,a5)
321 #define SimTK_ERRCHK6(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6)
322 #define SimTK_ERRCHK7(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6)
324 #define SimTK_ERRCHK(cond,whereChecked,msg) \
325 SimTK_ERRCHK_ALWAYS(cond,whereChecked,msg)
326 #define SimTK_ERRCHK1(cond,whereChecked,fmt,a1) \
327 SimTK_ERRCHK1_ALWAYS(cond,whereChecked,fmt,a1)
328 #define SimTK_ERRCHK2(cond,whereChecked,fmt,a1,a2) \
329 SimTK_ERRCHK2_ALWAYS(cond,whereChecked,fmt,a1,a2)
330 #define SimTK_ERRCHK3(cond,whereChecked,fmt,a1,a2,a3) \
331 SimTK_ERRCHK3_ALWAYS(cond,whereChecked,fmt,a1,a2,a3)
332 #define SimTK_ERRCHK4(cond,whereChecked,fmt,a1,a2,a3,a4) \
333 SimTK_ERRCHK4_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4)
334 #define SimTK_ERRCHK5(cond,whereChecked,fmt,a1,a2,a3,a4,a5) \
335 SimTK_ERRCHK5_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4,a5)
336 #define SimTK_ERRCHK6(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6) \
337 SimTK_ERRCHK6_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6)
338 #define SimTK_ERRCHK7(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6,a7) \
339 SimTK_ERRCHK7_ALWAYS(cond,whereChecked,fmt,a1,a2,a3,a4,a5,a6,a7)
349 #define SimTK_ASSERT_ALWAYS(cond,msg) \
350 do{if(!(cond))SimTK_THROW2(SimTK::Exception::Assert,#cond,(msg));}while(false)
351 #define SimTK_ASSERT1_ALWAYS(cond,msg,a1) \
352 do{if(!(cond))SimTK_THROW3(SimTK::Exception::Assert,#cond,(msg),(a1));}while(false)
353 #define SimTK_ASSERT2_ALWAYS(cond,msg,a1,a2) \
354 do{if(!(cond))SimTK_THROW4(SimTK::Exception::Assert,#cond,(msg),(a1),(a2));}while(false)
355 #define SimTK_ASSERT3_ALWAYS(cond,msg,a1,a2,a3) \
356 do{if(!(cond))SimTK_THROW5(SimTK::Exception::Assert,#cond,(msg),(a1),(a2),(a3));}while(false)
357 #define SimTK_ASSERT4_ALWAYS(cond,msg,a1,a2,a3,a4) \
358 do{if(!(cond))SimTK_THROW6(SimTK::Exception::Assert,#cond,(msg),(a1),(a2),(a3),(a4));}while(false)
359 #define SimTK_ASSERT5_ALWAYS(cond,msg,a1,a2,a3,a4,a5) \
360 do{if(!(cond))SimTK_THROW7(SimTK::Exception::Assert,#cond,(msg),(a1),(a2),(a3),(a4),(a5));}while(false)
365 #if defined(NDEBUG) && !defined(SimTK_KEEP_ASSERT)
366 #define SimTK_ASSERT(cond,msg)
367 #define SimTK_ASSERT1(cond,msg,a1)
368 #define SimTK_ASSERT2(cond,msg,a1,a2)
369 #define SimTK_ASSERT3(cond,msg,a1,a2,a3)
370 #define SimTK_ASSERT4(cond,msg,a1,a2,a3,a4)
371 #define SimTK_ASSERT5(cond,msg,a1,a2,a3,a4,a5)
373 #define SimTK_ASSERT(cond,msg) SimTK_ASSERT_ALWAYS(cond,msg)
374 #define SimTK_ASSERT1(cond,msg,a1) SimTK_ASSERT1_ALWAYS(cond,msg,a1)
375 #define SimTK_ASSERT2(cond,msg,a1,a2) SimTK_ASSERT2_ALWAYS(cond,msg,a1,a2)
376 #define SimTK_ASSERT3(cond,msg,a1,a2,a3) SimTK_ASSERT3_ALWAYS(cond,msg,a1,a2,a3)
377 #define SimTK_ASSERT4(cond,msg,a1,a2,a3,a4) SimTK_ASSERT4_ALWAYS(cond,msg,a1,a2,a3,a4)
378 #define SimTK_ASSERT5(cond,msg,a1,a2,a3,a4,a5) SimTK_ASSERT5_ALWAYS(cond,msg,a1,a2,a3,a4,a5)
382 #endif // SimTK_SimTKCOMMON_EXCEPTION_MACROS_H_