Subj : Re: Supressing errors? To : Brian Genisio From : Brendan Eich Date : Fri Jan 30 2004 11:58 am Brian Genisio wrote: > Hi all, > > I was wondering what the best way to supress specific errors are? I > can think of couple ways to do it, but none are extremely keen in my > book. > > Here is where I want to supress the error: > > When a non-numeric string is passed to JS_ValueToInt32, an error is > reported, and it returns false. All I care about is that we return > false. If I get false, I will use a default value, and move on. Do you want JS_ValueToECMAInt32 instead? JS_ValueToInt32 range-errors if the value doesn't convert to a number, or if it converts to a number that doesn't fit in a 32-bit signed int; then it rounds to nearest. JS_ValueToECMAInt32 takes non-finite (NaN, +/-Infinity) as 0, then computes fmod of the number with 2^32, then truncates the fmod result toward zero. The practical differences are: 1. fmod vs. range error; 2. round to nearest vs. truncation toward zero. > I would rather not print an error when I use the method in this way, > but I dont know a _good_ way of detecting that we dont care about the > error. Error suppression is done in the engine, and can be done using the API. See JS_SetErrorReporter, JS_SaveExceptionState, JS_RestoreExceptionState, and JS_DropExceptionState. /be .