sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Name : terminate_handler_test.cpp sl@0: // Part of : standard c++ tests. sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "test_decls.h" sl@0: #include sl@0: #include sl@0: sl@0: int glob_val = 0; sl@0: sl@0: class UserClass{ sl@0: public: sl@0: ~UserClass() { sl@0: throw int (0); // This causes std::terminate to be called since the sl@0: // destructor is throwing while someone is unwinding the stack. sl@0: // Since we ahve the terminate_handler set, my_handler must get called. sl@0: } sl@0: }; sl@0: sl@0: sl@0: void foo() { sl@0: UserClass uc; sl@0: throw int (1); // causes stack unwinding - hence calls ~UserClass() sl@0: } sl@0: sl@0: sl@0: void bar() { sl@0: try { sl@0: foo(); sl@0: }catch(...){} sl@0: } sl@0: sl@0: void my_handler() sl@0: { sl@0: glob_val = 1; sl@0: CPP_TESTS_ASSERT_ALLWAYS(1); sl@0: abort(); sl@0: } sl@0: sl@0: int main() sl@0: { sl@0: std::terminate_handler h_old, h_new; sl@0: h_new = (std::terminate_handler)&my_handler; sl@0: h_old = std::set_terminate(h_new); sl@0: h_old = h_old; sl@0: bar(); sl@0: sl@0: //Failed to call terminate handler sl@0: CPP_TESTS_ASSERT_ALLWAYS(0); sl@0: sl@0: return 0; sl@0: }