GNU Octave  8.1.0
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-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <cstring>
31 
32 #include <ostream>
33 #include <sstream>
34 #include <new>
35 
36 #include "quit.h"
37 
38 sig_atomic_t octave_interrupt_state = 0;
39 
40 volatile sig_atomic_t octave_signal_caught = 0;
41 
42 void (*octave_signal_hook) (void) = nullptr;
43 void (*octave_interrupt_hook) (void) = nullptr;
44 
46 
47 std::string execution_exception::stack_trace (void) const
48 {
49  std::size_t nframes = m_stack_info.size ();
50 
51  if (nframes == 0)
52  return std::string ();
53 
54  std::ostringstream buf;
55 
56  buf << "error: called from\n";
57 
58  for (const auto& frm : m_stack_info)
59  {
60  buf << " " << frm.fcn_name ();
61 
62  int line = frm.line ();
63 
64  if (line > 0)
65  {
66  buf << " at line " << line;
67 
68  int column = frm.column ();
69 
70  if (column > 0)
71  buf << " column " << column;
72  }
73 
74  buf << "\n";
75  }
76 
77  return buf.str ();
78 }
79 
80 void execution_exception::display (std::ostream& os) const
81 {
82  if (! m_message.empty ())
83  {
84  os << m_err_type << ": " << m_message;
85 
86  if (m_message.back () != '\n')
87  {
88  os << "\n";
89 
90  std::string st = stack_trace ();
91 
92  if (! st.empty ())
93  os << st;
94  }
95  }
96 }
97 
99 
100 void
102 {
103  if (octave_signal_hook)
105 
106  if (octave_interrupt_state > 0)
107  {
109 
110  throw octave::interrupt_exception ();
111  }
112 }
OCTAVE_END_NAMESPACE(octave)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
volatile sig_atomic_t octave_signal_caught
Definition: quit.cc:40
sig_atomic_t octave_interrupt_state
Definition: quit.cc:38
void(* octave_interrupt_hook)(void)
Definition: quit.cc:43
void(* octave_signal_hook)(void)
Definition: quit.cc:42
void octave_handle_signal(void)
Definition: quit.cc:101