How to catch errors that occur during System.Windows.Forms.A

Posted by cverbiest on 09-Oct-2014 07:15

I'm trying to catch errors that occur in events that fire during the wait-for.

The error is not caught instead it is shown by the default progress dialog.

If it is not possible to catch this, is there a way to replace the default error dialog box .

def var myMenu as MainMenu. 
myMenu = new MainMenu(). 

do on error undo, retry: 
    myMenu:Show(). 
    wait-for System.Windows.Forms.Application:Run (myMenu). 
    CATCH e AS Progress.Lang.Error : 
        MESSAGE "Caught error" e:getmessage(1) skip
         e:callstack VIEW-AS ALERT-BOX. 
    END CATCH. 
end.


To run the sample:

  • unzip,
  • run main.p
  • press the button to start the second form,
  • leaving the first textbox empty throws an error.

Posted by Mike Fechner on 09-Oct-2014 07:27

Hi Carl,
 
errors raised during the execution of the Application:Run () like a runtime error in the constructor of that Form (or code executed from there) or problems finding Assemblies during the loading of the initial Form will be handled by the CATCH block on the WAIT-FOR will already be terminated. In your sample this is everything happening directly related to the instantiation and the execution of the Show method for the MainMenu form.
 
Then you are in the event loop handling. Everything else from there is a response to user interaction and executed from event handlers.
 
Progress does not allow you to implement a default error handler. This is something worth an Idea – if there is not one already.
 
That’s why we do suggest to always have a default CATCH block at the end of every Event handler method. Because that’s typically the end of the user interaction and when something went wrong that can’t be handled otherwise, we at least want to inform the user in a more beautiful message than the Progress default behavior. Typically other code that is invoked from Event handlers will only have a CATCH block when there is something reasonable we can do to handle an error (workaround, alternative behavior).
 
Mike

All Replies

Posted by Mike Fechner on 09-Oct-2014 07:27

Hi Carl,
 
errors raised during the execution of the Application:Run () like a runtime error in the constructor of that Form (or code executed from there) or problems finding Assemblies during the loading of the initial Form will be handled by the CATCH block on the WAIT-FOR will already be terminated. In your sample this is everything happening directly related to the instantiation and the execution of the Show method for the MainMenu form.
 
Then you are in the event loop handling. Everything else from there is a response to user interaction and executed from event handlers.
 
Progress does not allow you to implement a default error handler. This is something worth an Idea – if there is not one already.
 
That’s why we do suggest to always have a default CATCH block at the end of every Event handler method. Because that’s typically the end of the user interaction and when something went wrong that can’t be handled otherwise, we at least want to inform the user in a more beautiful message than the Progress default behavior. Typically other code that is invoked from Event handlers will only have a CATCH block when there is something reasonable we can do to handle an error (workaround, alternative behavior).
 
Mike

Posted by cverbiest on 09-Oct-2014 07:34

Hi Mike,

I was afraid this would be the answer. I'll post an idea/enhancement request

Posted by Mike Fechner on 09-Oct-2014 07:39

Hi Carl, I haven't checked yet if the JET templates for new methods allow to detect if the method is an event handler either by a direct argument passed to the JET template code or by looking at the parameters.

If that would be possible, that would be a way to avoid that your team will have to consider this every day.

This thread is closed