Catch an Exception thrown by another form

后端 未结 4 1507
无人及你
无人及你 2021-01-19 10:48

I\'m trying to do this:

I\'m creating another form, which in it\'s FormClosed method throws an exception, that should be caught by the main form.

Main Form:<

4条回答
  •  悲哀的现实
    2021-01-19 11:15

    I don't think this can work, the new form is not running in the context of your code above, it is only being launched by it. If you check the stacktrace for the exception thrown you shouldn't see the code above in it, so it can't catch the exception.

    Update: I just created a test project & tried it. The stacktrace knows nothing about the original form. If you want to catch unhandled exceptions you may want to check out this question Unhandled Exception Handler in .NET 1.1

提交回复
热议问题