In modern advanced languages, most languages have keywords for handling exceptions, such as the try/except/finally in Try/catch,delphi in C + +, which are directly supported by the compiler.
However, when Symbian OS C + + was invented, the keyword try/catch/finally in C + + was not yet supported by standards. And, according to Symbian, the exception handling mechanism of C + + is cumbersome and lightweight, and they design an exception handling mechanism that is more efficient and more suitable for small, memory-constrained devices.
I. Review of History
in standard C + +, we use the following methods to handle exceptions:
void DoTest() {
try {
int n = 1 / 0;
}
catch (...) {
// do something...
throw;
}
}
PS: Standard C + + does not support finally.
Obviously, when the program executes to line 2nd, it throws an exception, and then jumps to line 5th to perform exception handling, using throw in line 6th to throw the exception to the outside.
Ii. Change of concept
Exception handling in Symbian OS C + + and standard C + + exception handling are similar. First we'll write the exception handling code in standard C + + in the following ways
void DoDiv() {
int n = 1 / 0;
}
void DoTest() {
try {
DoDiv();
}
catch(...) {
// do Something...
throw;
}
}
First, you can extract the possible error-extraction method into Dodiv and call Dodiv in the exception-handling capture statement in Dotest.