Re: Error Handling Advice [message #82702 is a reply to message #82701] |
Mon, 14 January 2013 13:02   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
David Fanning writes:
> 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
Or, even simpler:
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 RETURN
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.")
|
|
|