[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: snmpconf PM: Integer NaN?

>>>>> Steve Waldbusser writes:

Steve> The thing I'm interested in learning is which is better for the
Steve> programmer, bracketing with isInteger() or checking the
Steve> expression value for NaN. The most interesting difference
Steve> between them is that isInteger is checked before the conversion
Steve> and NaN is checked after the conversion. For example:


Modern programming languages have a concept of exceptions which you
can catch and handle:

    try {
       // Retrieve 1 digit decimal integer at 7th byte of octet string object
       str = getVar("xxx");
       i = substr(str, 7, 1);
       value = i * 1000;
    catch (conversion-error) {

The general idea here is to stop execution as soon as you have an
exception (which is IMHO a good thing) and to pass the error up the
call stack for someone to catch and handle it. Additional constructs
such as "finally" make it easier to have cleanup code.

[I am sending this just to make it clear that this thread is about
 general exception handling and that there are more general ways to
 address this than inventing specific test functions or special values
 for certain data types.]


Juergen Schoenwaelder      Technical University Braunschweig
<schoenw@ibr.cs.tu-bs.de>  Dept. Operating Systems & Computer Networks
Phone: +49 531 391 3289    Bueltenweg 74/75, 38106 Braunschweig, Germany
Fax:   +49 531 391 5936    <URL:http://www.ibr.cs.tu-bs.de/~schoenw/>