Networking, Programming and Graphics Tutorials

Exception Handling - C++ [1/2]

Type:
Exception Handling - C++
Level: Expert Networking, Programming and Graphics Tutorials Networking, Programming and Graphics Tutorials Networking, Programming and Graphics Tutorials 
Exception Handling - C++
Date: 2006-Dec-12
Exception Handling - C++
Visited: 7363 times
Exception Handling - C++
Rating: Exception Handling - C++
Exception Handling - C++
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 - Exception Handling - C++ [1/2] - Networking, Programming and Graphics Tutorials

Need a specific tutorial? Do not hesitate and submit a request!
Related Tags: exception handling in C++ : throw(exception)  exception handling in C++  exception handling c++  Exception handling C++  exception handling c++ .net  "exception handling in c++"  exception handling inc++  exception handling, c++  exception handling "C++"  exception handling+c++   exception handling in c++  Exception Handling + C++  about exception handling in c++  "exception handling"+c++  exception handling C++  about exception handling  exception handling with C++  example of exception handling in C++  exception handling in c++ with example  Example for Exception Handling in C++