Mir
fatal.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2014 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 2 or 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * ---
17  * Fatal error handling - Fatal errors are situations we don't expect to ever
18  * happen and don't have logic to gracefully recover from. The most useful
19  * thing you can do in that situation is abort to get a clean core file and
20  * stack trace to maximize the chances of it being readable.
21  *
22  * Author: Daniel van Vugt <daniel.van.vugt@canonical.com>
23  * Alan Griffiths <alan@octopull.co.uk>
24  */
25 
26 #ifndef MIR_FATAL_H_
27 #define MIR_FATAL_H_
28 
29 namespace mir
30 {
40 extern void (*fatal_error)(char const* reason, ...);
41 
47 void fatal_error_except(char const* reason, ...);
48 
54 void fatal_error_abort(char const* reason, ...);
55 
56 // Utility class to override & restore existing error handler
58 {
59 public:
60  explicit FatalErrorStrategy(void (*fatal_error_handler)(char const* reason, ...)) :
61  old_fatal_error_handler(fatal_error)
62  {
63  fatal_error = fatal_error_handler;
64  }
65 
67  {
68  fatal_error = old_fatal_error_handler;
69  }
70 
71 private:
72  void (*old_fatal_error_handler)(char const* reason, ...);
73  FatalErrorStrategy(FatalErrorStrategy const&) = delete;
74  FatalErrorStrategy& operator=(FatalErrorStrategy const&) = delete;
75 };
76 } // namespace mir
77 
78 #endif // MIR_FATAL_H_
Definition: fatal.h:58
FatalErrorStrategy(void(*fatal_error_handler)(char const *reason,...))
Definition: fatal.h:60
~FatalErrorStrategy()
Definition: fatal.h:66
Definition: splash_session.h:24
void fatal_error_abort(char const *reason,...)
An alternative to fatal_error_except() that kills the program and dump core as cleanly as possible.
void fatal_error_except(char const *reason,...)
Throws an exception that will typically kill the Mir server and propagate from mir::run_mir.
void(* fatal_error)(char const *reason,...)
fatal_error() is strictly for "this should never happen" situations that you cannot recover from.

Copyright © 2012-2021 Canonical Ltd.
Generated on Tue Mar 30 08:30:24 UTC 2021
This documentation is licensed under the GPL version 2 or 3.