quit.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2002-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include <cstring>
00028 
00029 #include <iostream>
00030 #include <new>
00031 
00032 #include "quit.h"
00033 
00034 void (*octave_signal_hook) (void) = 0;
00035 void (*octave_interrupt_hook) (void) = 0;
00036 void (*octave_bad_alloc_hook) (void) = 0;
00037 
00038 void
00039 octave_handle_signal (void)
00040 {
00041   if (octave_signal_hook)
00042     octave_signal_hook ();
00043 
00044   if (octave_interrupt_state > 0)
00045     {
00046       octave_interrupt_state = -1;
00047       octave_throw_interrupt_exception ();
00048     }
00049 }
00050 
00051 void
00052 octave_throw_interrupt_exception (void)
00053 {
00054   if (octave_interrupt_hook)
00055     octave_interrupt_hook ();
00056 
00057   throw octave_interrupt_exception ();
00058 }
00059 
00060 void
00061 octave_throw_execution_exception (void)
00062 {
00063   // FIXME -- would a hook function be useful here?
00064 
00065   octave_exception_state = octave_exec_exception;
00066 
00067   throw octave_execution_exception ();
00068 }
00069 
00070 void
00071 octave_throw_bad_alloc (void)
00072 {
00073   if (octave_bad_alloc_hook)
00074     octave_bad_alloc_hook ();
00075 
00076   octave_exception_state = octave_alloc_exception;
00077 
00078   throw std::bad_alloc ();
00079 }
00080 
00081 void
00082 octave_rethrow_exception (void)
00083 {
00084   if (octave_interrupt_state)
00085     {
00086       octave_interrupt_state = -1;
00087       octave_throw_interrupt_exception ();
00088     }
00089   else
00090     {
00091       switch (octave_exception_state)
00092         {
00093         case octave_exec_exception:
00094           octave_throw_execution_exception ();
00095           break;
00096 
00097         case octave_alloc_exception:
00098           octave_throw_bad_alloc ();
00099           break;
00100 
00101         default:
00102           break;
00103         }
00104     }
00105 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines