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

Home » Public Forums » archive » error handling
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
error handling [message #1347] Thu, 26 August 1993 11:44 Go to next message
jabarone is currently offline  jabarone
Messages: 15
Registered: May 1993
Junior Member
Is there a way to do true error handling in IDL. I've read about the
ON_ERROR and MESSAGE procedures in the manuals, but the information
given isn't much help.

Given two procedures A and B. If A calls B and somewhwere in the execution
of B an error is triggered, is there a way to truely "handle" that error.
ie. can procedure A regain control, recognize that an error has occured
in B, and do something to handle the error, without halting the entire
program.


Please email replies.

Thanks,


John
jabarone@athena.mit.edu
Re: error handling [message #63440 is a reply to message #1347] Mon, 10 November 2008 11:42 Go to previous message
bulrushmower is currently offline  bulrushmower
Messages: 19
Registered: February 2008
Junior Member
On Nov 10, 1:06 pm, bulrushmo...@gmail.com wrote:
> On Nov 10, 12:12 pm, David Fanning <n...@dfanning.com> wrote:
>
>
>
>
>
>> bulrushmo...@gmail.com writes:
>>> Here is my source code. I am using MCTK tool to convert MODIS HDF
>>> data. The data processing is just converting the projection. It always
>>> runst for nearly a hundred data, then stops, saying 'can not attach
>>> the grid file...etc'. I would like to have the code right down the
>>> error in the log file, and then continue the loop for the next data.
>
>> Well, if this code runs for "nearly a hundred times",
>> and as you appear to be opening a logical unit number
>> with your ENVI_BATCH_INIT command, but not closing it--
>> I would say you are probably just running out of logical
>> unit numbers, since there are only "about 100" available.
>
>> I'm not sure CATCH error handling will help in this
>> case. Any chance you can close the logical unit
>> number ENVI opens?
>
>> Cheers,
>
>> David
>
>> --
>> David Fanning, Ph.D.
>> Coyote's Guide to IDL Programming (www.dfanning.com)
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> It happened when even I did not set up that Envi_batch_unit, and write
> a log file.
> Is the code about error handling is in right track? Am I missing
> something?
>
> Thanks- Hide quoted text -
>
> - Show quoted text -

Indeed, I tried to process the data 125 each time. It works fine, no
any error reported. Original processings was stopped at almost after
processing 206 data. So, there is something the logical unit of the
data. But, I could not figure out what is that.

thanks
Re: error handling [message #63441 is a reply to message #1347] Mon, 10 November 2008 11:06 Go to previous message
bulrushmower is currently offline  bulrushmower
Messages: 19
Registered: February 2008
Junior Member
On Nov 10, 12:12 pm, David Fanning <n...@dfanning.com> wrote:
> bulrushmo...@gmail.com writes:
>> Here is my source code. I am using MCTK tool to convert MODIS HDF
>> data. The data processing is just converting the projection. It always
>> runst for nearly a hundred data, then stops, saying 'can not attach
>> the grid file...etc'. I would like to have the code right down the
>> error in the log file, and then continue the loop for the next data.
>
> Well, if this code runs for "nearly a hundred times",
> and as you appear to be opening a logical unit number
> with your ENVI_BATCH_INIT command, but not closing it--
> I would say you are probably just running out of logical
> unit numbers, since there are only "about 100" available.
>
> I'm not sure CATCH error handling will help in this
> case. Any chance you can close the logical unit
> number ENVI opens?
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Coyote's Guide to IDL Programming (www.dfanning.com)
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

It happened when even I did not set up that Envi_batch_unit, and write
a log file.
Is the code about error handling is in right track? Am I missing
something?

Thanks
Re: error handling [message #63442 is a reply to message #1347] Mon, 10 November 2008 10:12 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
bulrushmower@gmail.com writes:

> Here is my source code. I am using MCTK tool to convert MODIS HDF
> data. The data processing is just converting the projection. It always
> runst for nearly a hundred data, then stops, saying 'can not attach
> the grid file...etc'. I would like to have the code right down the
> error in the log file, and then continue the loop for the next data.

Well, if this code runs for "nearly a hundred times",
and as you appear to be opening a logical unit number
with your ENVI_BATCH_INIT command, but not closing it--
I would say you are probably just running out of logical
unit numbers, since there are only "about 100" available.

I'm not sure CATCH error handling will help in this
case. Any chance you can close the logical unit
number ENVI opens?

Cheers,

David

--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: error handling [message #63443 is a reply to message #1347] Mon, 10 November 2008 09:54 Go to previous message
bulrushmower is currently offline  bulrushmower
Messages: 19
Registered: February 2008
Junior Member
On Nov 10, 11:23 am, Reimar Bauer <R.Ba...@fz-juelich.de> wrote:
> bulrushmo...@gmail.com schrieb:
>
>
>
>
>
>> On Nov 10, 7:38 am, David Fanning <n...@dfanning.com> wrote:
>>> Spon writes:
>>>> bulrushmo...@gmail.com writes:
>>>> > How can I set up that when error happens, IDL output the error message
>>>> > to log file, then igonore that step continue to process next data?.
>>>> Something like this:
>>>>   OpenW, lun, 'logfile.out', /GET_LUN
>>>>   FOR j=0,n DO BEGIN
>>>>      Catch, theError
>>>>      IF theError NE 0 THEN BEGIN
>>>>         PrintF, lun, 'Problem with processing step ' + StrTrim(j)
>>>>         CONTINUE
>>>>      ENDIF
>>>>      DoSomeProcessing, data[j]
>>>>   ENDFOR
>>>>   Catch, /Cancel
>>>>   Free_Lun, lun
>>>> Excuse my ignorance on this, but wouldn't you need to stick your
>>>> "Catch, /Cancel" INSIDE the for loop?
>>>> If not, why not?
>>> There is no requirement for when you cancel a CATCH, except
>>> you should cancel it when you are finished with it. While CATCH
>>> is in effect, any error is re-routed to the first line after
>>> the CATCH statement. When cancelled, any error is routed
>>> to the ON_ERROR condition in effect for that program
>>> module. In a real code example, rather than cancelling
>>> the CATCH there, I would probably have had another CATCH
>>> statement to replace the one I was using for the process
>>> loop.
>
>>> Cheers,
>
>>> David
>>> --
>>> David Fanning, Ph.D.
>>> Fanning Software Consulting, Inc.
>>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")- Hide quoted text -
>
>>> - Show quoted text -
>
>> The problem is even I use these statements, program still halted when
>> enounter a bad data.
>> Should I place the Catch, /cancel inside the loop.
>> Another issue, should I state the Catch, the error  right after the
>> beginning the loop, or after the image processing, end of the loop?
>
>> thanks
>
> If you can show your source, e.g. use a pastebin
> we usually can better help
>
> cheers
> Reimar- Hide quoted text -
>
> - Show quoted text -

Here is my source code. I am using MCTK tool to convert MODIS HDF
data. The data processing is just converting the projection. It always
runst for nearly a hundred data, then stops, saying 'can not attach
the grid file...etc'. I would like to have the code right down the
error in the log file, and then continue the loop for the next data.
Thanks

Pro convert_test
out_path = 'define the path here'
in_path = 'define the path here'
envi, /restore_base_save_files
envi_batch_init, BATCH_LUN=batch_unit, log_file = out_path +
modisdata.txt'
files = file_search(in_path, '*.HDF', count=count)
FOR i = 0, count-1 do begin
CATCH, Error_status
IF Error_status NE 0 THEN BEGIN
printF, batch_unit, 'Error index: ', Error_status
printF, batch_unit, 'Error message: ', !ERROR_STATE.MSG
PrintF, batch_unit, 'Problem with processing step ',
files[K]
CONTINUE
Catch, /Cancel
ENDIF
modis_grid_file = files[i]
variable = variable
......

convert_modis_data, variable=variable,...

ENDFOR


end
Re: error handling [message #63447 is a reply to message #1347] Mon, 10 November 2008 09:23 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
bulrushmower@gmail.com schrieb:
> On Nov 10, 7:38 am, David Fanning <n...@dfanning.com> wrote:
>> Spon writes:
>>> bulrushmo...@gmail.com writes:
>>>> How can I set up that when error happens, IDL output the error message
>>>> to log file, then igonore that step continue to process next data?.
>>> Something like this:
>>> OpenW, lun, 'logfile.out', /GET_LUN
>>> FOR j=0,n DO BEGIN
>>> Catch, theError
>>> IF theError NE 0 THEN BEGIN
>>> PrintF, lun, 'Problem with processing step ' + StrTrim(j)
>>> CONTINUE
>>> ENDIF
>>> DoSomeProcessing, data[j]
>>> ENDFOR
>>> Catch, /Cancel
>>> Free_Lun, lun
>>> Excuse my ignorance on this, but wouldn't you need to stick your
>>> "Catch, /Cancel" INSIDE the for loop?
>>> If not, why not?
>> There is no requirement for when you cancel a CATCH, except
>> you should cancel it when you are finished with it. While CATCH
>> is in effect, any error is re-routed to the first line after
>> the CATCH statement. When cancelled, any error is routed
>> to the ON_ERROR condition in effect for that program
>> module. In a real code example, rather than cancelling
>> the CATCH there, I would probably have had another CATCH
>> statement to replace the one I was using for the process
>> loop.
>>
>> Cheers,
>>
>> David
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.dfanning.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")- Hide quoted text -
>>
>> - Show quoted text -
>
> The problem is even I use these statements, program still halted when
> enounter a bad data.
> Should I place the Catch, /cancel inside the loop.
> Another issue, should I state the Catch, the error right after the
> beginning the loop, or after the image processing, end of the loop?
>
> thanks

If you can show your source, e.g. use a pastebin
we usually can better help

cheers
Reimar
Re: error handling [message #63453 is a reply to message #1347] Mon, 10 November 2008 07:11 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
bulrushmower@gmail.com writes:

> The problem is even I use these statements, program still halted when
> enounter a bad data.
> Should I place the Catch, /cancel inside the loop.
> Another issue, should I state the Catch, the error right after the
> beginning the loop, or after the image processing, end of the loop?

Well, I have *NO* idea what you are doing in the processing
step, so I have no way of helping you. I can only presume
that the error handling in your processing routines are
such that the error returns to the CATCH. This can easily
not be the case. (For example, your processing routines
might not have any error handling in them at all!) Plus, the
errors can be I/O errors, which are typically handled in a
different way (with ON_IOERROR).

Lots of things can be going on here that I am depending
on you to sort out. I was only answering the question
in a general way. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: error handling [message #63455 is a reply to message #1347] Mon, 10 November 2008 07:02 Go to previous message
bulrushmower is currently offline  bulrushmower
Messages: 19
Registered: February 2008
Junior Member
On Nov 10, 7:38 am, David Fanning <n...@dfanning.com> wrote:
> Spon writes:
>> bulrushmo...@gmail.com writes:
>>> How can I set up that when error happens, IDL output the error message
>>> to log file, then igonore that step continue to process next data?.
>
>> Something like this:
>
>>   OpenW, lun, 'logfile.out', /GET_LUN
>>   FOR j=0,n DO BEGIN
>
>>      Catch, theError
>>      IF theError NE 0 THEN BEGIN
>>         PrintF, lun, 'Problem with processing step ' + StrTrim(j)
>>         CONTINUE
>>      ENDIF
>
>>      DoSomeProcessing, data[j]
>>   ENDFOR
>>   Catch, /Cancel
>>   Free_Lun, lun
>
>> Excuse my ignorance on this, but wouldn't you need to stick your
>> "Catch, /Cancel" INSIDE the for loop?
>> If not, why not?
>
> There is no requirement for when you cancel a CATCH, except
> you should cancel it when you are finished with it. While CATCH
> is in effect, any error is re-routed to the first line after
> the CATCH statement. When cancelled, any error is routed
> to the ON_ERROR condition in effect for that program
> module. In a real code example, rather than cancelling
> the CATCH there, I would probably have had another CATCH
> statement to replace the one I was using for the process
> loop.
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")- Hide quoted text -
>
> - Show quoted text -

The problem is even I use these statements, program still halted when
enounter a bad data.
Should I place the Catch, /cancel inside the loop.
Another issue, should I state the Catch, the error right after the
beginning the loop, or after the image processing, end of the loop?

thanks
Re: error handling [message #63456 is a reply to message #1347] Mon, 10 November 2008 05:38 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Spon writes:

> bulrushmo...@gmail.com writes:
>> How can I set up that when error happens, IDL output the error message
>> to log file, then igonore that step continue to process next data?.
>
> Something like this:
>
> � OpenW, lun, 'logfile.out', /GET_LUN
> � FOR j=0,n DO BEGIN
>
> � � �Catch, theError
> � � �IF theError NE 0 THEN BEGIN
> � � � � PrintF, lun, 'Problem with processing step ' + StrTrim(j)
> � � � � CONTINUE
> � � �ENDIF
>
> � � �DoSomeProcessing, data[j]
> � ENDFOR
> � Catch, /Cancel
> � Free_Lun, lun
>
> Excuse my ignorance on this, but wouldn't you need to stick your
> "Catch, /Cancel" INSIDE the for loop?
> If not, why not?

There is no requirement for when you cancel a CATCH, except
you should cancel it when you are finished with it. While CATCH
is in effect, any error is re-routed to the first line after
the CATCH statement. When cancelled, any error is routed
to the ON_ERROR condition in effect for that program
module. In a real code example, rather than cancelling
the CATCH there, I would probably have had another CATCH
statement to replace the one I was using for the process
loop.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: error handling [message #63458 is a reply to message #1347] Mon, 10 November 2008 04:40 Go to previous message
Spon is currently offline  Spon
Messages: 178
Registered: September 2007
Senior Member
On Nov 10, 12:24 am, David Fanning <n...@dfanning.com> wrote:
> bulrushmo...@gmail.com writes:
>> How can I set up that when error happens, IDL output the error message
>> to log file, then igonore that step continue to process next data?.
>
> Something like this:
>
>   OpenW, lun, 'logfile.out', /GET_LUN
>   FOR j=0,n DO BEGIN
>
>      Catch, theError
>      IF theError NE 0 THEN BEGIN
>         PrintF, lun, 'Problem with processing step ' + StrTrim(j)
>         CONTINUE
>      ENDIF
>
>      DoSomeProcessing, data[j]
>   ENDFOR
>   Catch, /Cancel
>   Free_Lun, lun
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Excuse my ignorance on this, but wouldn't you need to stick your
"Catch, /Cancel" INSIDE the for loop?
If not, why not?

Regards,
Chris
Re: error handling [message #63463 is a reply to message #1347] Sun, 09 November 2008 20:59 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
bulrushmower@gmail.com writes:

> Frustrating!!
> I tried whole afternoon, did not work.
> My program like this:
> files =3D file_search(input_location,'*.dat', count=3DnumFiles)
> For i=3D0, numFiles do begin
>
> CATCH, Error_status
>
> IF Error_status NE 0 THEN BEGIN
> printF, batch_unit, 'Error index: ', Error_status
> printF, batch_unit, 'Error message: ', !ERROR_STATE.MSG
> PrintF, batch_unit, 'Problem with processing step ',
> files[K]
>
> ;
> CONTINUE
> ENDIF
>
> dosomedataprocessings, file[k]
>
> ENDFOR
>
> Catch, /Cancel

What didn't work about it?

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: error handling [message #63464 is a reply to message #1347] Sun, 09 November 2008 20:40 Go to previous message
bulrushmower is currently offline  bulrushmower
Messages: 19
Registered: February 2008
Junior Member
On Nov 9, 6:24 pm, David Fanning <n...@dfanning.com> wrote:
> bulrushmo...@gmail.com writes:
>> How can I set up that when error happens, IDL output the error message
>> to log file, then igonore that step continue to process next data?.
>
> Something like this:
>
>   OpenW, lun, 'logfile.out', /GET_LUN
>   FOR j=0,n DO BEGIN
>
>      Catch, theError
>      IF theError NE 0 THEN BEGIN
>         PrintF, lun, 'Problem with processing step ' + StrTrim(j)
>         CONTINUE
>      ENDIF
>
>      DoSomeProcessing, data[j]
>   ENDFOR
>   Catch, /Cancel
>   Free_Lun, lun
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Frustrating!!
I tried whole afternoon, did not work.
My program like this:
files = file_search(input_location,'*.dat', count=numFiles)
For i=0, numFiles do begin

CATCH, Error_status

IF Error_status NE 0 THEN BEGIN
printF, batch_unit, 'Error index: ', Error_status
printF, batch_unit, 'Error message: ', !ERROR_STATE.MSG
PrintF, batch_unit, 'Problem with processing step ',
files[K]

;
CONTINUE
ENDIF

dosomedataprocessings, file[k]

ENDFOR

Catch, /Cancel
Re: error handling [message #63465 is a reply to message #1347] Sun, 09 November 2008 17:20 Go to previous message
bulrushmower is currently offline  bulrushmower
Messages: 19
Registered: February 2008
Junior Member
On Nov 9, 6:24 pm, David Fanning <n...@dfanning.com> wrote:
> bulrushmo...@gmail.com writes:
>> How can I set up that when error happens, IDL output the error message
>> to log file, then igonore that step continue to process next data?.
>
> Something like this:
>
>   OpenW, lun, 'logfile.out', /GET_LUN
>   FOR j=0,n DO BEGIN
>
>      Catch, theError
>      IF theError NE 0 THEN BEGIN
>         PrintF, lun, 'Problem with processing step ' + StrTrim(j)
>         CONTINUE
>      ENDIF
>
>      DoSomeProcessing, data[j]
>   ENDFOR
>   Catch, /Cancel
>   Free_Lun, lun
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

thank you!
Re: error handling [message #63466 is a reply to message #1347] Sun, 09 November 2008 16:24 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
bulrushmower@gmail.com writes:

> How can I set up that when error happens, IDL output the error message
> to log file, then igonore that step continue to process next data?.

Something like this:

OpenW, lun, 'logfile.out', /GET_LUN
FOR j=0,n DO BEGIN

Catch, theError
IF theError NE 0 THEN BEGIN
PrintF, lun, 'Problem with processing step ' + StrTrim(j)
CONTINUE
ENDIF

DoSomeProcessing, data[j]
ENDFOR
Catch, /Cancel
Free_Lun, lun

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Plot: idl_guide4 UK_NCAS-Meteo-Library
Next Topic: Re: Empty arrays?

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

Current Time: Wed Oct 08 15:10:35 PDT 2025

Total time taken to generate the page: 0.00919 seconds