Subj : Re: Supressing errors? To : netscape.public.mozilla.jseng From : Brendan Eich Date : Fri Jan 30 2004 12:01 pm Brendan Eich wrote: > 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. Of course, JS_ValueToECMAInt32 will throw an error exception if you pass it a string value beginning with other than a numeric literal (possibly preceded by whitespace). Why do you want to suppress errors? Users who make mistakes, obvious or subtle, will be left scratching their heads. With try/catch/finally exception handling in JS and ECMA for many years now, it seems to me much better to give the user some signal that something is amiss. /be .