Mercurial > octave
annotate libinterp/corefcn/panic.h @ 33247:55e1412aca35
call error instead of abort in panic_impossible, panic_if, and panic_unless
* error.cc (error_system::vpanic): Call ::verror to issue message and
throw error instead of printing message directly to std::error and
calling abort.
* panic.h: Fix comment.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 25 Mar 2024 00:43:53 -0400 |
parents | d9ed1a322311 |
children | ab68bff7b8b8 |
rev | line source |
---|---|
33243
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 // |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
3 // Copyright (C) 2024 The Octave Project Developers |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 // |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 // |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 // This file is part of Octave. |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 // |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 // (at your option) any later version. |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 // |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 // GNU General Public License for more details. |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 // |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 // |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 #if ! defined (octave_panic_h) |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 #define octave_panic_h 1 |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 #include "octave-config.h" |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include <cstdarg> |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 OCTAVE_NORETURN |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 extern OCTINTERP_API void vpanic (const char *fmt, va_list args); |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 OCTAVE_FORMAT_PRINTF (1, 2) |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 OCTAVE_NORETURN |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 extern OCTINTERP_API void panic (const char *fmt, ...); |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 // To allow the __FILE__ and __LINE__ macros to work as expected, the |
33247
55e1412aca35
call error instead of abort in panic_impossible, panic_if, and panic_unless
John W. Eaton <jwe@octave.org>
parents:
33243
diff
changeset
|
41 // panic_impossible, panic_if, and panic_unless symbols must be defined |
55e1412aca35
call error instead of abort in panic_impossible, panic_if, and panic_unless
John W. Eaton <jwe@octave.org>
parents:
33243
diff
changeset
|
42 // as macros. |
33243
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 #define panic_impossible() \ |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 ::panic ("impossible state reached in file '%s' at line %d", __FILE__, __LINE__) |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 #if defined (NDEBUG) |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 # define panic_if(cond) |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 #else |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 # define panic_if(cond) do { if (cond) panic_impossible (); } while (0) |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 #endif |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 #if defined (NDEBUG) |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 # define panic_unless(cond) |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 #else |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 # define panic_unless(cond) panic_if (! (cond)) |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 #endif |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 |
d9ed1a322311
move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 #endif |