A simple exception handling using C#

By | April 23, 2011


See how a very simple exception handling works with try-catch methods using C#.

using System;

class MainClass{

    public static void Main(){

        int divOne = 0;

        try {
            int ans = 79 / divOne ;

        catch (Exception e) {
            Console.WriteLine("You got the exception-> " + e.Message);


Output- “You got the exception-> Attempted to divide by zero.”


One thought on “A simple exception handling using C#

  1. momochi

    Finally, an issue that I am passionate about. I have looked for information of this caliber for the last several hours. Your site is greatly appreciated.


Leave a Reply

Your email address will not be published. Required fields are marked *