GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
quit.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2002-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <cstring>
28 
29 #include <iostream>
30 #include <new>
31 
32 #include "quit.h"
33 
34 void (*octave_signal_hook) (void) = nullptr;
35 void (*octave_interrupt_hook) (void) = nullptr;
36 void (*octave_bad_alloc_hook) (void) = nullptr;
37 
38 void
40 {
43 
44  if (octave_interrupt_state > 0)
45  {
48  }
49 }
50 
51 void
52 clean_up_and_exit (int exit_status, bool /* safe_to_return */)
53 {
54  exit (exit_status);
55 }
56 
57 void
59 {
62 
63  throw octave::interrupt_exception ();
64 }
65 
66 void
68 {
69  // FIXME: would a hook function be useful here?
70 
72 
73  throw octave::execution_exception ();
74 }
75 
76 void
78 {
81 
83 
84  throw std::bad_alloc ();
85 }
86 
87 void
88 octave_throw_exit_exception (int exit_status, int safe_to_return)
89 {
91 
92 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
93 # pragma GCC diagnostic push
94 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
95 #endif
96 
97  throw octave_exit_exception (exit_status, safe_to_return);
98 
99 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
100 # pragma GCC diagnostic pop
101 #endif
102 }
103 
104 void
106 {
108  {
111  }
112  else
113  {
114  switch (octave_exception_state)
115  {
118  break;
119 
122  break;
123 
124 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
125 # pragma GCC diagnostic push
126 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
127 #endif
128 
132  break;
133 
134 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
135 # pragma GCC diagnostic pop
136 #endif
137 
138  default:
139  break;
140  }
141  }
142 }
sig_atomic_t octave_exit_exception_safe_to_return
Definition: cquit.c:43
void octave_throw_interrupt_exception(void)
Definition: quit.cc:58
sig_atomic_t octave_exit_exception_status
Definition: cquit.c:41
void octave_throw_execution_exception(void)
Definition: quit.cc:67
void octave_handle_signal(void)
Definition: quit.cc:39
sig_atomic_t octave_exception_state
Definition: cquit.c:34
void(* octave_signal_hook)(void)
Definition: quit.cc:34
sig_atomic_t octave_interrupt_state
Definition: cquit.c:32
void octave_throw_bad_alloc(void)
Definition: quit.cc:77
void octave_throw_exit_exception(int exit_status, int safe_to_return)
Definition: quit.cc:88
void(* octave_interrupt_hook)(void)
Definition: quit.cc:35
void octave_rethrow_exception(void)
Definition: quit.cc:105
void clean_up_and_exit(int exit_status, bool)
Definition: quit.cc:52
void(* octave_bad_alloc_hook)(void)
Definition: quit.cc:36