//: C01:Nonlocal.cpp
// From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison.
// (c) 1995-2004 MindView, Inc. All Rights Reserved.
// See source code use permissions stated in the file 'License.txt',
// distributed with the code package available at www.MindView.net.
// setjmp() & longjmp().
#include <iostream>
#include <csetjmp>
using namespace std;

class Duha {
public:
  Duha() { cout << "Duha()" << endl; }
  ~Duha() { cout << "~Duha()" << endl; }
};

jmp_buf kansas;

void oz() {
  Duha du;
  for(int i = 0; i < 3; i++)
    cout << "Všude dobře, doma nejlépe" << endl;
  longjmp(kansas, 47);
}

int main() {
  if(setjmp(kansas) == 0) {
    cout << "tornádo, čarodějnice, pidimužíci..." << endl;
    oz();
  } else {
    cout << "Tetičko Em! "
         << "Zdál se mi ten nejdivnější sen..."
         << endl;
  }
	
} ///:~
