[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passing optional parameters through a wrapper routine



edward.s.meinel@aero.org wrote:
> 
>[...]
> Ugh, I *hate* MESSAGE. Why cause a crash when it is easy to exit nicely?
> How about:
> 
>   IF N_ELEMENTS(arg1) EQ 0 THEN BEGIN
>        print, 'You haven't defined arg1'
>        RETURN
>   ENDIF

You can still use MESSAGE to print out your warning. Just use the
/CONTINUE
keyword. What I like about message is that it tells you the routine
you're in.

> > if in doubt, stop and call for help.
> 
> Right, but you can stop and ask for help without forcing a crash. How
> about:
> 
> IF SIZE(arg2, /TNAME) NE 'STRING' THEN BEGIN
> 
> ; Oooops! forgot the file name.
> 
>   arg2 = DIALOG_PICKFILE(set_the_appropriate_keywords)
>   IF arg2 EQ '' THEN BEGIN
>     dummy = DIALOG_MESSAGE( $
>             'You must provide a file name as the second argument')
>     RETURN
>   ENDIF
> ENDIF

Oh, I think one could write whole books on error treatment (just that no
one would
read them, I fear ;-). I try to group errors into categories like:

FATAL AND FUNDAMENTAL: stop right here and there and tell the user to
ring me up in the middle of the night or at least send me mail

FATAL USER ERROR: tell the user what an idiot he/she is and quit
execution gracefully
  (message,...,/Continue & return)

SERIOUS ERROR: When in interactive mode, stop gracefully and complain;
when in batch mode, log the error into a file and continue. 

MILD ERROR: Complain and try to take corrective actions - in interactive
mode let the user decide how to continue (e.g. by showing the pickfile
dialog)

WARNING: Complain and continue

And maybe one should add 
DEBUG INFO: produce verbose output when debugging


Well, that's my philosophy - but I must admit, it's not always easy to
discipline myself to actually implement it...

Cheers,
Martin


-- 
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
[[ Dr. Martin Schultz   Max-Planck-Institut fuer Meteorologie    [[
[[                      Bundesstr. 55, 20146 Hamburg             [[
[[                      phone: +49 40 41173-308                  [[
[[                      fax:   +49 40 41173-298                  [[
[[ martin.schultz@dkrz.de                                        [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[