Exception handling

  • An exception is a run time error.
  • Exception Handler
    is a mechanism that handles an exception.
  • In C# exception handling is managed via try, catch, throw and finally.
  • Here's the general form of these statements:

    Syntax:    try

    {

        statement(s)

    }

    catch (exceptiontype name)

    {

    statement(s)

    }

    finally

    {

                statement(s)

    }

  • Program statements that you want to monitor for exceptions are contained within a try block. If an exception occurs within the try block, it is thrown.
  • Your code can catch these exceptions that are automatically thrown by the run-time system.
  • The finally statement must be associated with a try statement and identifies a block of statements that are executed regardless of whether or not an error occurs within the try block.
  • The throw statement is used explicitly to throw an exception.

0 comments :

Post a Comment

> Related Posts with Thumbnails
 

Copyright © 2012. GS dot net - All Rights Reserved - Design by BTDesigner - Proudly powered by Blogger