|
|
Programming ExceptionIn computer programming, a programming exception occurs when an error is discovered during the course of programming. The most commonly known one is a divide by zero error, meaning that a statement like 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 advant 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 supress 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 defination of an exception. For example, the user can introduce an 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!\n"); } catch (...) { printf("something else is wrong\n"); } finally { printf("A=%d", iA) } } end of code ---
|
 |