we’re having an application on server instance and quite rarely, but we have out of memory exception (program is not leaking, just instance is quite small and it operates with quite big amounts of data).
That would be not a problem, as we monitor processes on that server instance and if some of the processes are not found in process list, alert email is sent.
Now the problem is with this:

That prevents process from disappearing from process list, so we don’t get alert email about it’s failure. Is it possible to disable this message, that if program fails on something we don’t catch, it would close without user interaction?
Assuming Windows Forms, I typically do multiple steps to prevent this message box.
First, I connect several handlers in the
Mainfunction:Those handlers are being called when an otherwise unhandled exception occurs. I would define them something like:
The actual
doHandleExceptionfunction that is then called does the actual error handling. Usually this is logging the error and notifying the user, giving him the options to continue the application or quit it.An example from a real-world application looks like:
With the helper function:
If you are using not Windows Forms but e.g. a Console application or WPF, some handlers are not present, while others are present instead.
The idea stays the same: Subscribe to event handlers that are being called if you have no
try...catcharound your code blocks.Personally, I try to have as few of those
try...catchblocks as possible (ideally none).