|
Thinking In C++. Volume 2: Practical ProgrammingIf an exception does indeed occur, the contained object is not constructed, so it makes no sense to return to the code that created it. For this reason, the only sensible thing to do is to throw an exception in the function-level catch clause. Although it is not terribly useful, C++ also allows function-level try blocks for any function, as the following example illustrates: //: C01:FunctionTryBlock.cpp // Function-level try blocks //{-bor} #include <iostream> using namespace std; int main() try { В throw "main"; } catch(const char* msg) { cout << msg << endl; return 1; } ///:~ In this case, the catch block can return in the same manner that the function body normally returns. Using this type of function-level try block isn’t much different from inserting a try-catch around the code inside of the function body. Standard exceptions The set of exceptions used with the Standard C++ library is also available for your use. Generally it’s easier and faster to start with a standard exception class than to try to define your own ...» |
Код для вставки книги в блог HTML
phpBB
текст
|
|