comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Error Handling Advice
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Error Handling Advice [message #82703 is a reply to message #82702] Mon, 14 January 2013 12:58 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Matthew Argall writes:

>
>> I guess I will start with some with trial and ::ehem:: error ;-)
>
> So, after a little work, I get a cascade of error messages
>
> ----------------------------
> function add, a, b
> Catch, theError
> IF theError NE 0 THEN BEGIN
> Catch, /CANCEL
> void = Error_Message()
> RETURN, !Null
> ENDIF
>
> RETURN, a + b
> end
>
> pro call_add
> Catch, theError
> IF theError NE 0 THEN BEGIN
> Catch, /CANCEL
> void = Error_Message()
> RETURN
> ENDIF
>
> sum = add(a, b)
>
> IF sum EQ !Null THEN message, 'Sum not valid'
> END
> --------------------------------
>
> Should there be a STOP in there somewhere?

No, there are a TON of errors in this program. You might just as well
find all of them before you move on. :-)


> Is this were "add" would require an ON_ERROR, 2? I can imagine some cases where you would want to keep both CATCH statements...

I would probably write this particular set of routines like this.

function add, a, b, SUCCESS=success
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = Error_Message()
success = 0
RETURN, !Null
ENDIF

success = 1
result = a + b
RETURN, result
end

pro call_add
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
void = Error_Message()
RETURN
ENDIF

sum = add(a, b, SUCCESS=success)
IF ~success THEN RETURN

IF sum EQ !Null THEN message, 'Sum not valid'
END


Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Using function after .reset
Next Topic: Transparent and Overplotted Images with cgImage

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 06:21:38 PDT 2025

Total time taken to generate the page: 1.20058 seconds