Mercurial > octave-nkf
annotate libcruft/misc/quit.cc @ 14138:72c96de7a403 stable
maint: update copyright notices for 2012
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 02 Jan 2012 14:25:41 -0500 |
parents | 12df7854fa7c |
children |
rev | line source |
---|---|
4153 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3 Copyright (C) 2002-2012 John W. Eaton |
4153 | 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 the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
4153 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4153 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
4154 | 27 #include <cstring> |
28 | |
5142 | 29 #include <iostream> |
4180 | 30 #include <new> |
31 | |
4153 | 32 #include "quit.h" |
33 | |
5142 | 34 void (*octave_signal_hook) (void) = 0; |
4429 | 35 void (*octave_interrupt_hook) (void) = 0; |
36 void (*octave_bad_alloc_hook) (void) = 0; | |
37 | |
4153 | 38 void |
5142 | 39 octave_handle_signal (void) |
40 { | |
41 if (octave_signal_hook) | |
42 octave_signal_hook (); | |
43 | |
44 if (octave_interrupt_state > 0) | |
45 { | |
46 octave_interrupt_state = -1; | |
47 octave_throw_interrupt_exception (); | |
48 } | |
49 } | |
50 | |
51 void | |
4153 | 52 octave_throw_interrupt_exception (void) |
53 { | |
4429 | 54 if (octave_interrupt_hook) |
55 octave_interrupt_hook (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
56 |
4153 | 57 throw octave_interrupt_exception (); |
58 } | |
59 | |
4180 | 60 void |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
61 octave_throw_execution_exception (void) |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
62 { |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
63 // FIXME -- would a hook function be useful here? |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
64 |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
65 octave_exception_state = octave_exec_exception; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
66 |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
67 throw octave_execution_exception (); |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
68 } |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
69 |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
70 void |
4180 | 71 octave_throw_bad_alloc (void) |
72 { | |
4429 | 73 if (octave_bad_alloc_hook) |
74 octave_bad_alloc_hook (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
75 |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
76 octave_exception_state = octave_alloc_exception; |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
77 |
4181 | 78 throw std::bad_alloc (); |
4180 | 79 } |
80 | |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
81 void |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
82 octave_rethrow_exception (void) |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
83 { |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
84 if (octave_interrupt_state) |
10069
c670c8be7f93
fix incorrect octave_interrupt_state escaped from liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
85 { |
c670c8be7f93
fix incorrect octave_interrupt_state escaped from liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
86 octave_interrupt_state = -1; |
c670c8be7f93
fix incorrect octave_interrupt_state escaped from liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
87 octave_throw_interrupt_exception (); |
c670c8be7f93
fix incorrect octave_interrupt_state escaped from liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9933
diff
changeset
|
88 } |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
89 else |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
90 { |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
91 switch (octave_exception_state) |
10164
085d4e025155
libcruft/misc/quit.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10069
diff
changeset
|
92 { |
085d4e025155
libcruft/misc/quit.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10069
diff
changeset
|
93 case octave_exec_exception: |
085d4e025155
libcruft/misc/quit.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10069
diff
changeset
|
94 octave_throw_execution_exception (); |
085d4e025155
libcruft/misc/quit.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10069
diff
changeset
|
95 break; |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
96 |
10164
085d4e025155
libcruft/misc/quit.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10069
diff
changeset
|
97 case octave_alloc_exception: |
085d4e025155
libcruft/misc/quit.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10069
diff
changeset
|
98 octave_throw_bad_alloc (); |
085d4e025155
libcruft/misc/quit.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10069
diff
changeset
|
99 break; |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
100 |
10164
085d4e025155
libcruft/misc/quit.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10069
diff
changeset
|
101 default: |
085d4e025155
libcruft/misc/quit.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10069
diff
changeset
|
102 break; |
085d4e025155
libcruft/misc/quit.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10069
diff
changeset
|
103 } |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
104 } |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
105 } |