2

In my UI application (WPF/C#, using MVVM design pattern), I have implemented a global exception handler which catches all unexpected (hence uncaught) exceptions and reports the application crash to the user via a dedicated "crash report" window.

Instead of bombarding the user with the entire stack trace right away, I'd like to have a single line of text which either says "No data was modified - you're on the safe side" or "Data processing was aborted - your data might be inconsistent" (or something like that). I guess this would reassure users about the extent of the failure.

To do so, my model would need to keep track of "safe sections" and "critical sections" and the crash report window would need to evaluate this application state.

I'm wondering if this is a good idea at all and, more important, what would be a suitable approach to implement this. I was thinking about adding a public property to the Application class (where my global exception handler already resides) and then bind the crash report view model to that. Maybe there is a better approach?

Do you have any references for me to get started?

Thank you very much in advance!

2

I have implemented a global exception handler which catches all unexpected (hence uncaught) exceptions and reports the application crash to the user via a dedicated "crash report" window.

OK. It's [marginally] better than nothing. I'm going to assume that you "useful" Exception Handling further down in the Application.

Instead of bombarding the user with the entire stack trace right away ...

Never show a Stack Trace to a User.

Stack Traces are big, scary, screen-filling noise.

What would you expect the User to do with a Stack Trace anyway?

In the same way that code often cannot do anything "useful" with an Exception, Users can never do anything "useful" with one, so don't waste their time with it. Given them a Message and that's about it.

Of course, you should log the entire Exception to somewhere from which it can be retrieved later, but do not put it in front of the User in its entirety.

I'd like to have a single line of text which either says "No data was modified - you're on the safe side" or "Data processing was aborted - your data might be inconsistent" ... the crash report window would need to evaluate this application state.

The Application state is "Dead".

Or as near to it as makes no odds.

You cannot reliably determine anything about the "state" of the Application from the stratospherically high viewpoint of a "global" Exception Handler - all the details have long since been blasted aside by the Exception's rocket-like ascent through the call stack.

Short answer:

If something goes badly enough wrong that it "takes out" the whole Application, which is the only time that a global Exception Handler would be invoked, then all bets are off; there's nothing you can reliably do to tell the User what was happening at the time.
Even if you could write the code to do so, you might very well, say, trigger the same OutOfMemoryException that was thrown in the first place, thereby masking the real problem with an Exception of your [crash report window's] own!

The best you can get should be the logged Exception that you can retrieve later.

  • 1
    "Give them a message and that's about it" - this was the kind of clear statement I was looking for :-D – mister.nobody Oct 16 '19 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.