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

Home » Public Forums » archive » Catched in a catch loop
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
Catched in a catch loop [message #94799] Wed, 18 October 2017 06:48 Go to next message
LNpellen is currently offline  LNpellen
Messages: 37
Registered: November 2009
Member
I'm not used to CATCH - I strive to write the code robust enough to not cause errors. No I need it and seem to not understand how.

Using RESTORE with a not valid save file causes
% RESTORE: Not a valid save file:

So I try with this catch, but the error occurs even though I get the dialog With the error-message I wrote (looping until I have to crash the program).

What have I misunderstood?



CATCH, err_stat
IF err_stat NE 0 THEN BEGIN
CATCH, /CANCEL
sv=DIALOG_MESSAGE('Not valid .sav file: '+adr, /INFORMATION)
ENDIF
RESTORE, adr



-Ellen
Re: Catched in a catch loop [message #94800 is a reply to message #94799] Wed, 18 October 2017 07:10 Go to previous messageGo to next message
Jim  Pendleton is currently offline  Jim Pendleton
Messages: 165
Registered: November 2011
Senior Member
On Wednesday, October 18, 2017 at 7:48:37 AM UTC-6, LNpellen wrote:
> I'm not used to CATCH - I strive to write the code robust enough to not cause errors. No I need it and seem to not understand how.
>
> Using RESTORE with a not valid save file causes
> % RESTORE: Not a valid save file:
>
> So I try with this catch, but the error occurs even though I get the dialog With the error-message I wrote (looping until I have to crash the program).
>
> What have I misunderstood?
>
>
>
> CATCH, err_stat
> IF err_stat NE 0 THEN BEGIN
> CATCH, /CANCEL
> sv=DIALOG_MESSAGE('Not valid .sav file: '+adr, /INFORMATION)
> ENDIF
> RESTORE, adr
>
>
>
> -Ellen

You will want a RETURN of some sort after your DIALOG_MESSAGE call otherwise the code will continue to run past the ENDIF statement. In this case it would execute the RESTORE a second time and stop.
Re: Catched in a catch loop [message #94801 is a reply to message #94799] Wed, 18 October 2017 07:21 Go to previous messageGo to next message
Markus Schmassmann is currently offline  Markus Schmassmann
Messages: 129
Registered: April 2016
Senior Member
On 10/18/2017 03:48 PM, LNpellen wrote:
> I'm not used to CATCH - I strive to write the code robust enough to
> not cause errors. No I need it and seem to not understand how.
>
> Using RESTORE with a not valid save file causes
> % RESTORE: Not a valid save file:
>
> So I try with this catch, but the error occurs even though I get the
> dialog With the error-message I wrote (looping until I have to crash
> the program).
>
> What have I misunderstood?
>
>
> CATCH, err_stat
> IF err_stat NE 0 THEN BEGIN
> CATCH, /CANCEL
> sv=DIALOG_MESSAGE('Not valid .sav file: '+adr, /INFORMATION)
> ENDIF
> RESTORE, adr

after pressing OK in the dialog window, the process continues, i.e. it
tries again to run

RESTORE, adr

therefore after the line

sv=DIALOG_MESSAGE('Not valid .sav file: '+adr, /INFORMATION)

you have to either do something to fix adr to a correct filename, or
you have to abort the process, e.g. by a RETURN


alternatively you can replace the DIALOG_MESSAGE function by

message, 'Not valid .sav file: '+adr

in which case the program would stop at this line and the user could
enter a correct filename by entering at the console

IDL> adr='filename.sav'
IDL> .c


another possibility,

adr = DIALOG_PICKFILE(filter='*.sav',/must_exist,title='Not valid .sav
file: '+adr)
if adr eq '' then begin message, 'no file selected' & return & endif

I hope one of these is what you are looking for, Markus
Re: Catched in a catch loop [message #94806 is a reply to message #94801] Wed, 18 October 2017 22:21 Go to previous message
LNpellen is currently offline  LNpellen
Messages: 37
Registered: November 2009
Member
Thank you! First I got a compilation error with the RETURN as it is within a function, but when I made it RETURN, -1 it worked out.

CATCH, err_stat
IF err_stat NE 0 THEN BEGIN
CATCH, /CANCEL
sv=DIALOG_MESSAGE('Not valid .sav file: '+adr, /INFORMATION)
RETURN, -1
ENDIF
RESTORE, adr
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: tvscl
Next Topic: tvscl

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

Current Time: Wed Oct 08 07:16:53 PDT 2025

Total time taken to generate the page: 0.00468 seconds