Wednesday, December 28, 2016

Get more details when an Error Exception is thrown in C#

When there is an issue in the C# code, the application will throw exceptions.

All these exceptions can be handled properly and also logged. Using Reflection, we can get the class name and the function name which caused the exception

Simply use the following catch block in all your try-catch functions and pass all the exception to the Utility class to handle it.

catch (Exception ex)
{

MethodBase method = System.Reflection.MethodBase.GetCurrentMethod();

string methodName = method.Name;

string className = method.ReflectedType.Name;

UtilClass.HandleError(className, methodName, ex);

}
 
Happy Coding !

No comments:

Post a Comment

All Blogs so far ...