error3.cpp

We use cookies. Read the Privacy and Cookie Policy

error3.cpp

#include ‹stl.h›

// Compile this code without defining OS_USE_EXCEPTIONS.

void my_handler(int code_, const char* str_) {

 cout ‹‹ "Caught " ‹‹ str_ ‹‹ "[code " ‹‹ code_ ‹‹ "]" ‹‹ endl;

}

int main() {

 os_handler_function_t old_h = os_set_error_handler(my_handler);

 vector‹int› v;

 v.pop_back(); // Generates an empty object error.

 cout ‹‹ "returned from pop_back()" ‹‹ endl;

 os_set_error_handler(old_h);

 v.pop_back(); // Generates an empty object error.

 cout ‹‹ "successful termination" ‹‹ endl;

 return 0;

}