Symbian Learning Summary-Basic article-symbian exception Handling in C + +

Source: Internet
Author: User
Tags exception handling

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.