Cecilia,
CATCH is the more modern and best IDL command to use to catch an error for subsequent sending to an IDL DIALOG_MESSAGE message box. I paste an example below. The critical elements of error-handling, which you can subsequently look at in online help are CATCH and "CATCH, /CANCEL", the '!ERROR_STATE' structure, "HELP, /TRACEBACK", ON_ERROR and "MESSAGE, /REISSUE_LAST".
; This example is demonstrating three things:
; - the general syntax and use of a CATCH block which can
; display caught error messages in a system MessageBox
; - the more specialized syntax of a CATCH statement which is
; looking for a very specific error
; - the syntax of error handling which allows all other errors to
; be passed up the "call chain"
PRO ex_catch_error_in_messagebox
on_error, 2 ; Pass unhandled errors up to caller
catch, errno
if errno ne 0 then begin
catch, /CANCEL
; Handle only undefined variable error
if !error_state.name eq 'IDL_M_UNDEFVAR' then begin
help, /TRACEBACK, OUTPUT=helpOutput
void = dialog_message([!error_state.msg, 'Traceback Info:', $
helpOutput], /ERROR)
void = dialog_message(['Creating default value of', $
'-999.0 for undefined variable'], /INFO)
myVar = -999.0
endif else begin ; Propagate other errors up to the caller
message, /REISSUE_LAST ; Command to effect the propagation
endelse
endif
; Will trigger undefined variable error on first attempt
print, 'myVar = ', myVar
ENDJames Jones
|