The document discusses exception handling in programming languages. It introduces exceptions as data structures that store information about exceptional conditions. Exceptions can be thrown to transfer control to catch blocks. The document provides an example of throwing an exception if a number is greater than a stop number, and catching and trying the exception. Finally, it lists some reasons for using exceptions, such as avoiding unhandled errors, improving readability, exception safety, catching by solvers, and providing more information on exceptions.
2. Introduction
In programming language mechanisms for exception
handling, the term exception is typically used in a specific
sense to denote a data structure storing information about
an exceptional condition. One mechanism to transfer
control, or raise an exception, is known as a throw. The
exception is said to be thrown. Execution is transferred to a
"catch".
Reference: Wikipedia - Exception Handling http://en.
wikipedia.org/wiki/Exception_handling
3. How to use
Throw exception:
Catch and try:
if ( num > stopNum )
throw num;
try {
PrintSequence(20);
} catch ( int exNum ){
cout << "Caught an exception With value: " << ExNum
<< endl;
}
4. Maybe we will write this
● PrintSequence need to return a result.
● Condition for result.
● Define result.
result = PrintSequence(20);
if ( result == NE_NUM)
...
if ( result == NOT_NUM)
...
5. Why use exception
1. Avoid error never to handle.
2. Avoid our code unreadable.
3. Exception-safe
4. Catching exception with solver who
can solve.
5. Make exception architecture. (More
efficient categories)
6. More information on occur exception.