I'd like to have something like a "catch-all" for exceptions thrown from a inside a Control or a Form that reside within the current thread, but without resorting to using the Application.ThreadException
of the entire thread.
Why? Because I'd like to keep the exception handling modular.
All the code that can cause the problems is being run within a Form (DummyForm
) that is running within the current thread. I'd like to be able to wrap all of them in some other exception (DummyFormException
) that would identify that Form as the cause of the exception, so that if that exception makes it to the Application.ThreadException, I can know that the cleanup involves closing DummyForm
.
The alternatives, as I see them, are:
# Wrap every single thrown exception in the DummyForm
with a DummyFormException
. I don't like this so much, since it requires future programmers to remember to wrap each thrown exception, too.
# Run the DummyForm
in its own thread, and use Application.ThreadException
to catch them, and identify the thread inside that code. Once I know where it comes from, I could simply close the DummyForm
and end the thread.
Is there any way to do this without going multi-threaded? I'd hate to do it, it seems a waste just for error-handling. Or am I going about this all wrong?