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

Re: Surprising Odds and Ends



Martin Schultz (martin.schultz@dkrz.de) writes:

> Therefore, the solution should be to free the pointer
> within your event handler routine BEFORE calling the 
> cleanup routine.
> 
> In plain words:
> 
> CATCH, theError
> IF theError NE 0 THEN BEGIN
>    CATCH, /Cancel
>    Message,...
>    IF Ptr_Valid(info.thepointer) THEN Ptr_Free, info.thepointer
>    Cleanup
> ENDIF

Well, in plain words, this is right, although you can't
(well, "shouldn't" is a more accurate word) call the 
Cleanup procedure yourself. The Cleanup procedure is
called when the widget associated with it dies. The
CATCH would more likely look like this:

 CATCH, theError
 IF theError NE 0 THEN BEGIN
    CATCH, /Cancel
    Message,...
    IF N_Elements(info) NE 0 THEN $
       Widget_control, event.top, Set_UValue=info, /No_Copy
 ENDIF

> If the crash happens in a routine which you never expected to crash,
> well then you
> apparently caught an oversight by the programmer, and he should be told
> to fix the
> bug. In this case, a .reset_session usually helps ;-)

I'm a big fan of .Reset_Session, but I still see far too
many people in my travels who exit IDL every time they
crash a widget program because they have never heard of
RETALL and they can't ever get a widget program running
after one crashes! Getting those folks hooked on .Reset
would be just as bad. :-(

My problem is that I'm trying to tell a story in
some logical order and the denouement doesn't happen
until the hero gets burned almost beyond recognition
by asking for user input to read a file. Error Handling
is a nurse who brings him back to life and gives him
reason to live again. But I'm several chapters away 
from all of that. 

Cheers,

David

P.S. Let's just say the working title of my new book
is The IDL Patient. Catchy, don't you think. :-)
-- 
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155