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

Home » Public Forums » archive » Re: Catch problem
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Catch problem [message #23027] Tue, 02 January 2001 10:53
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
ALAN FRAZIER (s007amf@news.wright.edu) writes:

> Recently, I started learning the catch procedure to help with some error
> checking. I typed the code word-for-word out of the IDL 5.3
> documentation:
>
> PRO ABC
>
> A = fltarr(10)
>
> CATCH, Error_status
>
> IF Error_status NE O THEN BEGIN
> PRINT, 'ERROR INDEX: ', Error_Status
> PRINT, 'ERROR MESSAGE: ', !ERR_STRING
> A = FLTARR(12)
> ENDIF
>
> A[11] = 12
>
> HELP, A
>
> END
>
> to help me learn this command. However, this code does not seem to
> execute correctly. As far as I can tell, the code causes some sort of
> infinite loop on the if statement. Any ideas what I am doing wrong? I am
> using IDL 5.4 on a Mac.

There are two ways you can get into an infinite loop
in a CATCH error handler. (Well, two ways that I am
intimately familiar with.) First, you can have errors
in your error handling code. (Very, very bad, this one.)
Or, you can fail to fix the error in your error handing
code and continue to make the same error over and over
again. (I call this the "same spouse, different name"
syndrome.)

The secret to solving both of these problems is to
cancel the CATCH as the *FIRST* thing you do in the
error handling code (and pray that you can at least
spell *this* line correctly!). The second thing to
do is to exit the code (usually, unless you really
do know how to catch errors, in which case my hat
if off to you).

I like to use the ERROR_MESSAGE program on my web
page for error handling, because it prints out a
nice message that tells me where the actual error
occurred. This is handy if you want to fix the
error. :-)

CATCH, theError
IF theError NE 0 THEN BEGIN
CATCH, /Cancel
ok = Error_Message(/Traceback)
RETURN
ENDIF

You can find Error_Message here:

http://www.dfanning.com/programs/error_message.pro

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Catch problem [message #23028 is a reply to message #23027] Tue, 02 January 2001 10:27 Go to previous message
btt is currently offline  btt
Messages: 345
Registered: December 2000
Senior Member
Howdy,

I have done this all too frequently, Add ...

CATCH, /CANCEL

inside the if statement block so that the Error_Status value reverts to 0
(zero) before exiting the block. Error catching seems like big brother
watching to me... unlike the most of the procedures I know (maybe with the
exception of XMANAGER) where the action is history once the command is
given, CATCH keeps right on catching.

Ben



ALAN FRAZIER wrote:

> Recently, I started learning the catch procedure to help with some error
> checking. I typed the code word-for-word out of the IDL 5.3
> documentation:
>
> PRO ABC
>
> A = fltarr(10)
>
> CATCH, Error_status
>
> IF Error_status NE O THEN BEGIN
> PRINT, 'ERROR INDEX: ', Error_Status
> PRINT, 'ERROR MESSAGE: ', !ERR_STRING
> A = FLTARR(12)
> ENDIF
>
> A[11] = 12
>
> HELP, A
>
> END
>
> to help me learn this command. However, this code does not seem to
> execute correctly. As far as I can tell, the code causes some sort of
> infinite loop on the if statement. Any ideas what I am doing wrong? I am
> using IDL 5.4 on a Mac.
>
> --
> Alan

--
Ben Tupper
Bigelow Laboratory for Ocean Sciences
180 McKown Point Rd.
W. Boothbay Harbor, ME 04575
btupper@bigelow.org
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Catch problem
Next Topic: FILE_DELETE permissions ?

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

Current Time: Wed Oct 08 14:00:40 PDT 2025

Total time taken to generate the page: 0.00499 seconds