Unexpected behavior on Exception

An exception is not treated as I would expect. What do I need to do in order to get the expected behavior?

Here is the structure of the code.

  • This is a desktop application. It is intended to run on MacOS, Windows and Linux, but I run it on Windows only.
  • The application uses some API2 constructs in code but all the windows and all the controls are from the old API.
  • App handles the UnhandledException event.
  • No Exception statements are used.
  • There is no Try block involved in the relevant call stack.
  • In a menu item of the main window the following code is used: SettingsWindow.ShowModalWithin MainWindow
  • the settings window has an ‘Ok’ button. In it’s action event data from the window is saved and finally Close is called to dismiss the window. Here, while saving data I get an IOException.

In the GUI, the first time I click Ok, nothing happens (apparently). The second time I click Ok the UnhandledException event is triggered.

In the debugger with break on exception the following happens.

  • the debugger breaks on the line the exception is thrown/caused.
  • after continue running, the debugger breaks on the ShowModalWithin within statement with an IOException (likely the same exception, but how do I verify?).
  • after continue running, the application continues to work as if the exception was caught/handled. The SettingsWindow works as usual.
  • when I click the Ok button again, the debugger breaks on the same line as the first time, as the same error condition still persists
  • after continue running, the UnhandledException event is triggered.

Why is the exception “ignored” the first time? I would expect that is is handled by the UnhandledException event the first time.

Code? Example?

in short
method UnhandledException is not executed if a modal window is open.

usually executing of code is interrupted where .ShowModal is called and
continue if this window is closed or hide.

if you change it to .ShowWithin the UnhandledException cames direct as expected?

1 Like