Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to report standard exceptions to the user?

Consider a C# GUI application which uses a FileStream to read a file, chosen by the user through an "Open File" dialog.

In case the read fails with one of the exceptions, what is the correct way to report the failure to the user, in an user-friendly manner?

Should I invent my own message for each of those exceptions, or is there a way of obtaining a localized, user-friendly message that I could present verbatim to the user?

Edit

I'm asking whether .NET itself is able to provide me with a descriptive string that I can present (and which would be consistent with other .NET programs). I know that I can roll up my own, but I'd like to avoid that if there's a standard alternative.

like image 721
Kos Avatar asked Jul 01 '12 16:07

Kos


People also ask

Should default exceptions be shown to the user?

No, exceptions shouldn't be shown directly in error messages directly to the user, they're low level technical details and the user almost always wants something more understandable, even if it doesn't provide as much information as a stack trace would!

When to handle exception?

The method to choose depends on how often you expect the event to occur. Use exception handling if the event doesn't occur often, that is, if the event is truly exceptional and indicates an error, such as an unexpected end-of-file.

When to throw exceptions C++?

An exception should be thrown from a C++ constructor whenever an object cannot be properly constructed or initialized. Since there is no way to recover from failed object construction, an exception should be thrown in such cases.


1 Answers

You can have a set of localizable user exceptions with one of them being say FileUploadError. You can put a localized general information there. Throwing a few technical details might be a bit challenging, as it can be quite hard to get the right balance between technical details and a simple step that a user needs to take to fix an error.

My suggestion would be:

  1. Have one user level FileUploadErrorException
  2. Have a details property in it
  3. Depending on the actual exception, suggest a user to try a few things
like image 180
oleksii Avatar answered Nov 15 '22 22:11

oleksii