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

Home » Public Forums » archive » Re: combine CATCH and MESSAGE
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: combine CATCH and MESSAGE [message #77899] Tue, 27 September 2011 09:20
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
Thank you, that's what I was looking for !

nata
Re: combine CATCH and MESSAGE [message #77900 is a reply to message #77899] Tue, 27 September 2011 08:40 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
nata wrote:
> Hello guys,
>
> I used to use the CATCH method to catch the errors on my code but I
> also like the method using ON_ERROR,2 and MESSAGE.
> Right now, I would like to combine these 2 methods. Something like:
>
> PRO TEST, arg_1, ERROR=error
>
> CATCH, error_status
> IF error_status EQ 0 THEN BEGIN
> error=0
> IF N_ELEMENTS(arg_1) EQ 0 THEN MESSAGE, 'Incorrect number of
> arguments'
>
> ENDIF ELSE BEGIN
> error=1
> CATCH, /CANCEL
> ENDELSE
>
> END
>
> Note that in this routine, the output keyword error is very important.
> The problem here is that I want the message to cause the error and
> that is not happening. Do you know if there is a way to do that ? I
> mean without doing :
>
> IF N_ELEMENTS(arg_1) EQ 0 THEN BEGIN
> MESSAGE, Incorrect number of arguments', /INFORMATIONAL
> error=1
> RETURN
> ENDIF
>
> I also would like to ask for your opinion. I like the output keyword
> error, is very useful on my programs but I also like the MESSAGEs,
> they make the program very clear.
>
> Thanks for your help,

What about:

PRO TEST, arg_1, ERROR=error
error = 0 ; I presume this means "no error"
CATCH, Error_Status
IF ( Error_Status NE 0 ) THEN BEGIN
CATCH, /CANCEL
MESSAGE, !ERROR_STATE.MSG, /CONTINUE
error = 1
RETURN
ENDIF
...etc...

And then the actual error traps use the NONAME and NOPRINT switches to MESSAGE:

IF (N_ELEMENTS(arg_1) EQ 0) THEN $
MESSAGE, 'Incorrect number of arguments', $
/NONAME, /NOPRINT

?

cheers,

paulv
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: combine CATCH and MESSAGE
Next Topic: [Bug] Garbage collection with execute?

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

Current Time: Sat Oct 11 02:03:36 PDT 2025

Total time taken to generate the page: 1.59924 seconds