home *** CD-ROM | disk | FTP | other *** search
- //: C23:Nonlocal.cpp
- // From Thinking in C++, 2nd Edition
- // Available at http://www.BruceEckel.com
- // (c) Bruce Eckel 1999
- // Copyright notice in Copyright.txt
- // setjmp() & longjmp()
- #include <iostream>
- #include <csetjmp>
- using namespace std;
-
- class Rainbow {
- public:
- Rainbow() { cout << "Rainbow()" << endl; }
- ~Rainbow() { cout << "~Rainbow()" << endl; }
- };
-
- jmp_buf kansas;
-
- void oz() {
- Rainbow rb;
- for(int i = 0; i < 3; i++)
- cout << "there's no place like home\n";
- longjmp(kansas, 47);
- }
-
- int main() {
- if(setjmp(kansas) == 0) {
- cout << "tornado, witch, munchkins...\n";
- oz();
- } else {
- cout << "Auntie Em! "
- << "I had the strangest dream..."
- << endl;
- }
- } ///:~
-