Fanning Software Consulting

Widget Program Error Messages

QUESTION: My widget program produces the error: %XMANAGER: Caught unexpected error from client application. Message follows... % WIDGET_CONTROL: Invalid widget identifier: 61. This is not very descriptive. How can I get a more enlightened message?

ANSWER: Let me see if I can explain what is happening here, so you can solve the underlying problem a little more easily. The XManager routine has a CATCH statement in it. The way error handling in IDL works is that if there is a CATCH statement anywhere along the "program chain", then the error gets handled by that CATCH statement.

I don't know a good way to explain what I mean by program chain, but perhaps an example will suffice. If I call a program module I am one program away from the main program level of IDL. If that program in turn calls a program, and that program calls a third program, I am now three programs deep in the "chain" of programs that leads to the main IDL level. If an error occurs in the program module farthest from the main IDL level, the error will "bubble up" the program chain, much like an event bubbles up the widget hierarchy in a widget program, until it finds a CATCH error handler or it reaches the main IDL level.

What you really want is for the error in your widget program to bubble all the way up to the main IDL level, where IDL will attach a line number to the error. Then, at least, you will know what line of code caused the error, if not what the error message means exactly.

To make the error bubble all the way up, you have to turn any CATCH error handling off in the module that is causing the error (as well as in any module between it and the main IDL level), and you have to turn it off for XManager. You do the latter by typing this command on the IDL command line before you run your program:

   IDL> XManager, Catch=0

Now when you run the program, you might get an error message like this:

  % WIDGET_CONTROL: Invalid widget identifier: 3.
  % Execution halted at:  PICKFINISH_EVENT  323 C:\RSI\IDL51\david\picker.pro

Now you can go to line 323 in your code and have some idea of what the problem might be.

Of course, an even better idea would be to have error handling in your own code, so you don't have to rely on XManager to catch errors for you. Here is a simple Catch error handler that you can stick in almost any widget event handler module (or any other module for that matter). It will keep widget programs running smoothly and you will have intelligent error traceback messages, thanks to the cgErrorMsg program.

   Catch, theError
   IF theError NE 0 THEN BEGIN
      Catch, /Cancel
      void = Error_Message()
      RETURN
   ENDIF

Google
 
Web Coyote's Guide to IDL Programming