Exception Handling (1)
John 2012/06/19
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
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;
}
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)
...
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.

Java: Exception Handling

  • 1.
  • 2.
    Introduction In programming languagemechanisms 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 Throwexception: 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 willwrite 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.