Exception Handling in C#………

Exceptions are unforeseen errors that happen in your programs. Most of the time, you can, and should, detect and handle program errors in your code. For example, validating user input, checking for null objects, and verifying the values returned from methods are what you expect, are all examples of good standard error handling that you should be doing all the time.

There are two types of exceptions: exceptions generated by an executing program and exceptions generated by the common language runtime. System.Exception is the base class for all exceptions in C#. Several exception classes inherit from this class including ApplicationException and SystemException. These two classes form the basis for most other runtime exceptions. Other exceptions that derive directly from System.Exception include IOException, WebException etc.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Exception_HandlingDemo
    class Program
        static void Main(string[] args)
                int b = 0;
                int c = 100 / b;
                Console.WriteLine("Remaining try block");
                Console.WriteLine("Error Occured");
                Console.WriteLine("Finally block executed");

            Console.WriteLine("Remaining Code");



About Dinesh

I am engineering student........ I am selected in Microsoft Student Partner as MSP............

Posted on August 30, 2011, in .NET, C#, Knowledge. Bookmark the permalink. Leave a comment.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: