Tag: exception

How to Catch an Exception in C# ?

Every time when the exception is thrown , it is necessary that it be handled . In this case , one needs to wrap the code with the try catch block as shown below. How to Catch an Exception in C# ?

How to Catch the Unhandled Exceptions in C# ?

Are you looking for a way to catch the unhandled exception and perform the operation like logging etc. before the application terminates ?. Below is a sample code snippet that demonstrates how to do it in Console Application. How to Catch the Unhandled Exceptions in C# ?

How to Get Necessary Information from the Exception in C# ?

There are times when you want to get the necessary information from the exception to identify the error better in C# . The Exception class contains various properties which can be used to retreive the necessary information from the error. Some of the properties includes Message – The Message property provides the brief description of error. Source – The Source property provides information about the…

How to Rethrow an Exception in C# ?

There are times when you want to handle the exception and then pass it to the higher level . Below is a sample code snippet demonstrating how to Rethrow an exception in C# . How to Rethrow an Exception in C# ?

How to Throw an Exception in C# ?

To indicate and error which can be handled by the caller function , you can use the throw keyword to throw an exception . For example , below is a sample code snippet demonstrating how to throw an exception in C#. How to Throw an Exception in C# ?