- Category: ASP.NET
- #764358Best way to handle Exception is TRY...CATCH.
The basic rule of thumb for catching exceptions is to catch exceptions if and only if you have a meaningful way of handling them.
Don't catch an exception if you're only going to log the exception and throw it up the stack. It serves no meaning and clutters code.
Do catch an exception when you are expecting a failure in a specific part of your code, and if you have a fallback for it.
Of course you always have the case of checked exceptions which require you to use try/catch blocks, in which case you have no other choice. Even with a checked exception, make sure you log properly and handle as cleanly as possible
Editor, DotNetSpider MVM
Microsoft MVP 2014 [ASP.NET/IIS]
To show the exception to end user the preferable way to show it in Popup with meaningful message and at the same time for developer perspective better to track the logs in some fixed location, so that it will help to provide the solution with in time.
Of-course Try/ Catch blocks will help you to throw exceptions, If you get any exception in Try block then the exception will throw it in Catch block.
Give respect to your work, Instead of trying to impress your boss.
Blog : http://naveens-dotnet.blogspot.in/
- #764374It is completely depend on your application.
1. Try to create one global class to capture return value
public class OutResult
public int ErrorCode;
public string ErrorMsg;
public bool IsSucess;
2. Each and every call your can capture the error using "try..catch", "Custom error ", "validation error .." etc .
3. Show the user friendly error in the UI.
4. For Showing error is completely dependent on your application/UI.
* You can show div popup if it is critical error
* Show all error message in small div in the top of the application
* Show error messages near by the controls.
Direction is important than speed
- #764383Use like that:
If you are unable to do something properly for the first time, call it Version 1.0!
Thanks & Regards,
- #764397Hai Anbu,
We do have the try..catch block for the Exception handling in .Net technologies so you can make use of it.
Keep the logic which can have the suspect error and then use the catch block to handle it and you can get the message by the catch block exception class as below:
} catch(Exception ex)
Hope it will be helpful to you.
Pawan Awasthi(DNS MVM)
+91 8123489140 (whatsApp), +60 14365 1476(Malaysia)