1 // Copyright Maciej Sobczak 2008-2019.
2 // This file is part of YAMI4.
3 //
4 // YAMI4 is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // YAMI4 is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with YAMI4. If not, see <http://www.gnu.org/licenses/>.
16
17 #include "fatal_errors.h"
18 #include <cstdio>
19 #include <cstdlib>
20
21 using namespace yami;
22 using namespace yami::core;
23 using namespace yami::details;
24
25 namespace // unnamed
26 {
27
28 fatal_error_function custom_handler = NULL;
29
30 } // unnamed namespace
31
register_fatal_error_handler(fatal_error_function handler)32 void yami::core::register_fatal_error_handler(fatal_error_function handler)
33 {
34 custom_handler = handler;
35 }
36
fatal_failure(const char * source_file,int line_number)37 void yami::details::fatal_failure(const char * source_file, int line_number)
38 {
39 if (custom_handler != NULL)
40 {
41 try
42 {
43 custom_handler(source_file, line_number);
44 }
45 catch (...)
46 {
47 // ignore
48 }
49 }
50 else
51 {
52 std::printf("YAMI4 fatal error, see %s:%d\n",
53 source_file, line_number);
54 }
55
56 std::abort();
57 }
58