GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
quit.h
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 (octave_quit_h)
24 #define octave_quit_h 1
25 
26 #include "octave-config.h"
27 
28 /* The signal header is just needed for the sig_atomic_t type. */
29 #if defined (__cplusplus)
30 # include <csignal>
31 # include <string>
32 extern "C" {
33 #else
34 # include <signal.h>
35 #endif
36 
37 #if defined (__cplusplus)
38 
39 namespace octave
40 {
41  class
43  {
44  public:
45 
46  execution_exception (void) : m_stack_trace () { }
47 
49  : m_stack_trace (x.m_stack_trace) { }
50 
51  execution_exception& operator = (const execution_exception& x)
52  {
53  if (&x != this)
54  m_stack_trace = x.m_stack_trace;
55 
56  return *this;
57  }
58 
59  ~execution_exception (void) = default;
60 
61  virtual void set_stack_trace (const std::string& st)
62  {
63  m_stack_trace = st;
64  }
65 
66  virtual void set_stack_trace (void)
67  {
68  m_stack_trace = "";
69  }
70 
71  virtual std::string info (void) const
72  {
73  return m_stack_trace;
74  }
75 
76  private:
77 
78  std::string m_stack_trace;
79  };
80 
81  class
82  exit_exception
83  {
84  public:
85 
86  exit_exception (int exit_status = 0, bool safe_to_return = false)
87  : m_exit_status (exit_status), m_safe_to_return (safe_to_return)
88  { }
89 
90  exit_exception (const exit_exception& ex)
91  : m_exit_status (ex.m_exit_status), m_safe_to_return (ex.m_safe_to_return)
92  { }
93 
94  exit_exception& operator = (exit_exception& ex)
95  {
96  if (this != &ex)
97  {
98  m_exit_status = ex.m_exit_status;
99  m_safe_to_return = ex.m_safe_to_return;
100  }
101 
102  return *this;
103  }
104 
105  ~exit_exception (void) = default;
106 
107  int exit_status (void) const { return m_exit_status; }
108 
109  bool safe_to_return (void) const { return m_safe_to_return; }
110 
111  private:
112 
113  int m_exit_status;
114 
115  bool m_safe_to_return;
116  };
117 
118  class
119  interrupt_exception
120  {
121  };
122 }
123 
124 OCTAVE_DEPRECATED (4.2, "use 'octave::execution_exception' instead")
125 typedef octave::execution_exception octave_execution_exception;
126 
127 OCTAVE_DEPRECATED (4.2, "use 'octave::exit_exception' instead")
128 typedef octave::exit_exception octave_exit_exception;
129 
130 OCTAVE_DEPRECATED (4.2, "use 'octave::interrupt_exception' instead")
131 typedef octave::interrupt_exception octave_interrupt_exception;
132 
133 #endif
134 
136 {
141 };
142 
143 /*
144  > 0: interrupt pending
145  0: no interrupt pending
146  < 0: handling interrupt
147 */
148 OCTAVE_API extern sig_atomic_t octave_interrupt_state;
149 
150 OCTAVE_API extern sig_atomic_t octave_exception_state;
151 
152 OCTAVE_DEPRECATED (4.4, "see the Octave documentation for other options")
153 OCTAVE_API extern sig_atomic_t octave_exit_exception_status;
154 
155 OCTAVE_DEPRECATED (4.4, "see the Octave documentation for other options")
156 OCTAVE_API extern sig_atomic_t octave_exit_exception_safe_to_return;
157 
158 OCTAVE_API extern volatile sig_atomic_t octave_signal_caught;
159 
160 OCTAVE_API extern void octave_handle_signal (void);
161 
162 OCTAVE_NORETURN OCTAVE_API extern void octave_throw_interrupt_exception (void);
163 
164 OCTAVE_NORETURN OCTAVE_API extern void octave_throw_execution_exception (void);
165 
166 OCTAVE_NORETURN OCTAVE_API extern void octave_throw_bad_alloc (void);
167 
168 OCTAVE_DEPRECATED (4.4, "see the Octave documentation for other options")
169 OCTAVE_NORETURN OCTAVE_API extern void
170 octave_throw_exit_exception (int exit_status, int safe_to_return);
171 
172 OCTAVE_API extern void octave_rethrow_exception (void);
173 
174 #if defined (__cplusplus)
175 
176 OCTAVE_DEPRECATED (4.4, "see the Octave documentation for other options")
177 extern OCTAVE_API void
178 clean_up_and_exit (int exit_status, bool safe_to_return = false);
179 
180 inline void octave_quit (void)
181 {
183  {
186  }
187 };
188 
189 #define OCTAVE_QUIT octave_quit ()
190 
191 #else
192 
193 #define OCTAVE_QUIT \
194  do \
195  { \
196  if (octave_signal_caught) \
197  { \
198  octave_signal_caught = 0; \
199  octave_handle_signal (); \
200  } \
201  } \
202  while (0)
203 #endif
204 
205 /* The following macros are obsolete. Interrupting immediately by
206  calling siglongjmp or similar from a signal handler is asking for
207  trouble. We need another way to handle that situation. Rather
208  than remove them, however, please leave them in place until we can
209  either find a replacement or determine that a given block of code
210  does not need special treatment. They are defined to create a
211  dummy do-while block to match the previous definitions. */
212 
213 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \
214  do \
215  {
216 
217 #define END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \
218  } \
219  while (0)
220 
221 #if defined (__cplusplus)
222 
223 /* Likewise, these are obsolete. They are defined to create a
224  dummy scope to match the previous versions that created a try-catch
225  block. */
226 
227 #define BEGIN_INTERRUPT_WITH_EXCEPTIONS \
228  {
229 
230 #define END_INTERRUPT_WITH_EXCEPTIONS \
231  }
232 
233 #endif
234 
235 #if defined (__cplusplus)
236 }
237 
238 /* These should only be declared for C++ code, and should also be
239  outside of any extern "C" block. */
240 
241 extern OCTAVE_API void (*octave_signal_hook) (void);
242 extern OCTAVE_API void (*octave_interrupt_hook) (void);
243 extern OCTAVE_API void (*octave_bad_alloc_hook) (void);
244 
245 #endif
246 
247 #endif
octave_exception
Definition: quit.h:135
for(octave_idx_type n=0;n< hcv.numel();n++)
Definition: graphics.cc:10831
OCTAVE_API sig_atomic_t octave_interrupt_state
Definition: cquit.c:32
OCTAVE_NORETURN OCTAVE_API void octave_throw_execution_exception(void)
Definition: quit.cc:67
OCTAVE_API void octave_handle_signal(void)
Definition: quit.cc:39
OCTAVE_NORETURN OCTAVE_API void octave_throw_bad_alloc(void)
Definition: quit.cc:77
OCTAVE_API void octave_rethrow_exception(void)
Definition: quit.cc:105
is false
Definition: cellfun.cc:400
void(* octave_signal_hook)(void)
Definition: quit.cc:34
OCTAVE_NORETURN OCTAVE_API void octave_throw_exit_exception(int exit_status, int safe_to_return)
Definition: quit.cc:88
OCTAVE_API sig_atomic_t octave_exception_state
Definition: cquit.c:34
OCTAVE_NORETURN OCTAVE_API void octave_throw_interrupt_exception(void)
Definition: quit.cc:58
OCTAVE_API sig_atomic_t octave_exit_exception_status
Definition: cquit.c:41
OCTAVE_EXPORT octave_value_list only variables visible in the local scope are displayed The following are valid options
Definition: variables.cc:1862
OCTAVE_API sig_atomic_t octave_exit_exception_safe_to_return
Definition: cquit.c:43
void(* octave_interrupt_hook)(void)
Definition: quit.cc:35
void clean_up_and_exit(int exit_status, bool)
Definition: quit.cc:52
void(* octave_bad_alloc_hook)(void)
Definition: quit.cc:36
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
OCTAVE_API volatile sig_atomic_t octave_signal_caught
Definition: cquit.c:49
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x