Programming Exception Article Index for
Programming
Website Links For
Programming
 

Information About

Programming Exception





-- C code
---
{
A=0;
C = B/A;
}

-- end of code ---
is encountered (usually by the compiler or OS).

In the early days, the computer would usually crash, or return the user to the OS.
With the advent of structured exception handling, a programmer has the ability to compartmentalize the error to a certain scope in his code. The mechanism for compartmentalizing the code is the try/catch block. Hence in a segment of C code

--- C code

-
{
try {
A=0;
C = B/A;
} catch (...) {
printf("A is zero!");
}
}

-- end of code ---
one has the ability to structure the programming behavior and even suppress certain types of errors without subverting the original compilers design intent through the use of C/UNIX signals.
However, with structured programming handling, one has the ability to define new exceptions based on a user's definition of an exception. For example, the user can introduce a new exception which he defines.


--- C code

-
{
Exception DivideByZeroIntException;
try {
int iB, iC, iA=0;
if (0 == iA) throw DivideByZeroIntException;
iC = iB/iA;
} catch (DivideByZeroIntException) {
printf("A is zero!
");
} catch (...) {
printf("something else is wrong
");
} finally {
printf("A=%d", iA)
}
}

-- end of code ---