Javatpoint Logo
Javatpoint Logo

C# try/catch

In C# programming, exception handling is performed by try/catch statement. The try block in C# is used to place the code that may throw exception. The catch block is used to handled the exception. The catch block must be preceded by try block.

C# example without try/catch

Output:

Unhandled Exception: System.DivideByZeroException: Attempted to divide by zero.

C# try/catch example

Output:

System.DivideByZeroException: Attempted to divide by zero.
Rest of the code
Next TopicC# finally





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA