Re: how to catch a math error? [message #34804] |
Thu, 17 April 2003 12:55 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
J Li (anonymous@nowhere.com) writes:
> I am trying to figure out how to trap the math error and dump the error
> message to a file. Math error is somehow different than other types of
> errors? My test program is listed below.
>
> I have done tests for I/O error or raising an exception by issuing a
> "message" call. They all work as expected, that is I got error message in
> the myLog.err file and the program exited gracefully. So far, I have not
> been able to do the same for math error. Please help!
I'd try something like this:
pro test3
on_error, 2
print, "I am in test3"
junk = check_math()
x = 1 / 0
CASE check_math() OF
0:
1: Message, 'Integer divide by zero in Test 3.'
2: Message, 'Integer overflow in Test 3.'
16: Message, 'Floating point divide by zero in Test 3.'
32: Message, 'Floating point underflow in Test 3.'
64: Message, 'Floating point overflow in Test 3.'
128: Message, 'Floating point operand error in Test 3.'
ENDCASE
end
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|