Networking, Programming and Graphics Tutorials

Explain exception handling [1/2]

Type:
Explain exception handling
Level: Expert Networking, Programming and Graphics Tutorials Networking, Programming and Graphics Tutorials Networking, Programming and Graphics Tutorials 
Explain exception handling
Date: 2008-Jul-11
Explain exception handling
Visited: 1015 times
Explain exception handling
Rating: Explain exception handling
Explain exception handling
Author: Alex Plumpton

This tutorial will explain Exception Handling.
Exception handling allows you to manage run-time errors in an orderly fashion. In the 'C' program, every call to the function must be examined by the program. If else statement should surround each function call, and statements must be inserted to handle errors. The source code becomes large and difficult to read. Also some function cannot return an Errorvalue.

Example
if(somefunc() == ERROR_RETURN_VALUE)
//handle the error or call error-handler function
else
//proceed normally
if(another func()==NULL)
//handle the error or call error handler function
else
//proceed normally
if(thirdfunc()==0)
//handle the error or call-handler function
else
//proceed normally

The three keywords throw, try and catch are used to handle exceptions. Function returning using the exception handling mechanism is referred to as throwing an exception. The keyword throw is used to throw an exception. Try keyword surrounds a block of statements which may generate exception. Catch block catches the exception thrown by throw and handles them appropriately. The general forms of try and catch are shown above.

Means to Learn

Example
try
{
// try block
}
catch (type 1 arg){
// catch block
}
catch (type2 arg){
// catch block
}
catch (type3 arg){
// catch block 
}
Networking, Programming and Graphics Tutorials - Explain exception handling [1/2] - Networking, Programming and Graphics Tutorials

Need a specific tutorial? Do not hesitate and submit a request!
Related Tags: explain the exception handling with example  explain exception handling  Explain when exception handling should be used.  explain exception handling mechanisms   Explain the exception handling features of C++ with a simple program.  Explain the exception handling features of C++ with a simple program.  Explain the exception handling feature of c++ with a simple program  explain the exception handling features of c++ with a simple program  explain the exception handling features of C++ with a simple program.  "Explain the exception handling features of C++ with a simple program"