1*03a78d15Sespie // -*- C++ -*- std::terminate, std::unexpected and friends.
2*03a78d15Sespie // Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3*03a78d15Sespie // Free Software Foundation
4*03a78d15Sespie //
5*03a78d15Sespie // This file is part of GNU CC.
6*03a78d15Sespie //
7*03a78d15Sespie // GNU CC is free software; you can redistribute it and/or modify
8*03a78d15Sespie // it under the terms of the GNU General Public License as published by
9*03a78d15Sespie // the Free Software Foundation; either version 2, or (at your option)
10*03a78d15Sespie // any later version.
11*03a78d15Sespie //
12*03a78d15Sespie // GNU CC is distributed in the hope that it will be useful,
13*03a78d15Sespie // but WITHOUT ANY WARRANTY; without even the implied warranty of
14*03a78d15Sespie // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*03a78d15Sespie // GNU General Public License for more details.
16*03a78d15Sespie //
17*03a78d15Sespie // You should have received a copy of the GNU General Public License
18*03a78d15Sespie // along with GNU CC; see the file COPYING.  If not, write to
19*03a78d15Sespie // the Free Software Foundation, 59 Temple Place - Suite 330,
20*03a78d15Sespie // Boston, MA 02111-1307, USA.
21*03a78d15Sespie 
22*03a78d15Sespie // As a special exception, you may use this file as part of a free software
23*03a78d15Sespie // library without restriction.  Specifically, if other files instantiate
24*03a78d15Sespie // templates or use macros or inline functions from this file, or you compile
25*03a78d15Sespie // this file and link it with other files to produce an executable, this
26*03a78d15Sespie // file does not by itself cause the resulting executable to be covered by
27*03a78d15Sespie // the GNU General Public License.  This exception does not however
28*03a78d15Sespie // invalidate any other reasons why the executable file might be covered by
29*03a78d15Sespie // the GNU General Public License.
30*03a78d15Sespie 
31*03a78d15Sespie #include "typeinfo"
32*03a78d15Sespie #include "exception"
33*03a78d15Sespie #include <cstdlib>
34*03a78d15Sespie #include "unwind-cxx.h"
35*03a78d15Sespie #include "exception_defines.h"
36*03a78d15Sespie 
37*03a78d15Sespie using namespace __cxxabiv1;
38*03a78d15Sespie 
39*03a78d15Sespie /* The current installed user handlers.  */
40*03a78d15Sespie std::terminate_handler __cxxabiv1::__terminate_handler = std::abort;
41*03a78d15Sespie std::unexpected_handler __cxxabiv1::__unexpected_handler = std::terminate;
42*03a78d15Sespie 
43*03a78d15Sespie void
__terminate(std::terminate_handler handler)44*03a78d15Sespie __cxxabiv1::__terminate (std::terminate_handler handler)
45*03a78d15Sespie {
46*03a78d15Sespie   try {
47*03a78d15Sespie     handler ();
48*03a78d15Sespie     std::abort ();
49*03a78d15Sespie   } catch (...) {
50*03a78d15Sespie     std::abort ();
51*03a78d15Sespie   }
52*03a78d15Sespie }
53*03a78d15Sespie 
54*03a78d15Sespie void
terminate()55*03a78d15Sespie std::terminate ()
56*03a78d15Sespie {
57*03a78d15Sespie   __terminate (__terminate_handler);
58*03a78d15Sespie }
59*03a78d15Sespie 
60*03a78d15Sespie void
__unexpected(std::unexpected_handler handler)61*03a78d15Sespie __cxxabiv1::__unexpected (std::unexpected_handler handler)
62*03a78d15Sespie {
63*03a78d15Sespie   handler();
64*03a78d15Sespie   std::terminate ();
65*03a78d15Sespie }
66*03a78d15Sespie 
67*03a78d15Sespie void
unexpected()68*03a78d15Sespie std::unexpected ()
69*03a78d15Sespie {
70*03a78d15Sespie   __unexpected (__unexpected_handler);
71*03a78d15Sespie }
72*03a78d15Sespie 
73*03a78d15Sespie std::terminate_handler
set_terminate(std::terminate_handler func)74*03a78d15Sespie std::set_terminate (std::terminate_handler func) throw()
75*03a78d15Sespie {
76*03a78d15Sespie   std::terminate_handler old = __terminate_handler;
77*03a78d15Sespie   __terminate_handler = func;
78*03a78d15Sespie   return old;
79*03a78d15Sespie }
80*03a78d15Sespie 
81*03a78d15Sespie std::unexpected_handler
set_unexpected(std::unexpected_handler func)82*03a78d15Sespie std::set_unexpected (std::unexpected_handler func) throw()
83*03a78d15Sespie {
84*03a78d15Sespie   std::unexpected_handler old = __unexpected_handler;
85*03a78d15Sespie   __unexpected_handler = func;
86*03a78d15Sespie   return old;
87*03a78d15Sespie }
88