Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to show .net exception in more understandable way.
Posted

The only way is to catch the exception and 'translate' it to your language...
However, why end user ever should see an exception?
In our application, when unexpected error occurs (an exception) we log it into a DB with a unique number, and only inform the end user that an unexpected error has occurred and give away only the number in the log, with an option to send us the error by email...Later we check the log for the exact error and handle it as needed...
 
Share this answer
 
It depends on a number of factors:
1) Who your users are. If they are developers, then the "proper" error message is probably a little helpful - a connection string error, a "syntax error in INSERT", or similar tells them that it's probably your fault, rather than thiers, and they might want to try slightly differently. If they are "non-technical" then anything complicated is a mistake - and the approach Peter suggests in Solution 1 is best. In between? That's a balancing act.
2) It depends on the error! If it's an error in converting user input, then that's what you need to tell them - but you should be checking it yourself and reporting a very specific message "Please enter a valid date in the 'Date of Birth' box" rather than letting it get to an exception in the first place. If it's because the connection to the DB has died and you can't access data, then trapping DBException separately and reporting that "there is a problem communicating with the database, please try again later" is a good idea.
3) It depends what will happen as a result of the error. If it's a trivial problem that will impact just the character the user last typed, then the message isn't that important and a generic error message as given by the system is probably enough. If it means they are about to lose an hours work...then you better explain that in good detail! :laugh:

Generally, it's difficult to provide a "better" error than the one that comes with the exception for most users, provided that you trap specific exceptions such as DBException and such like instead of always using just the catch-all Exception object. Certainly there isn;t a single "better error" message you can use in all cases!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900