diff --git a/libinterp/corefcn/interpreter.cc b/libinterp/corefcn/interpreter.cc --- a/libinterp/corefcn/interpreter.cc +++ b/libinterp/corefcn/interpreter.cc @@ -322,14 +322,18 @@ safe_source_file (const std::string& fil { octave::source_file (file_name, context, verbose, require_file, warn_for); } - catch (const octave::interrupt_exception&) + catch (const octave::exit_exception&) { - octave::interpreter::recover_from_exception (); + // Catch and rethrow otherwise the (...) case will prevent + // us from exiting. - return 1; + throw; } - catch (const octave::execution_exception&) + catch (...) { + // Should we have special cases for classes of exceptions that we + // know about? What would we do differently in those cases? + octave::interpreter::recover_from_exception (); return 1; @@ -349,12 +353,18 @@ execute_pkg_add (const std::string& dir) { lp.execute_pkg_add (dir); } - catch (const octave::interrupt_exception&) + catch (const octave::exit_exception&) { - octave::interpreter::recover_from_exception (); + // Catch and rethrow otherwise the (...) case will prevent + // us from exiting. + + throw; } - catch (const octave::execution_exception&) + catch (...) { + // Should we have special cases for classes of exceptions that we + // know about? What would we do differently in those cases? + octave::interpreter::recover_from_exception (); } } @@ -835,6 +845,12 @@ namespace octave return 1; } + catch (const std::exception&) + { + recover_from_exception (); + + return 1; + } return parse_status; } @@ -997,6 +1013,13 @@ namespace octave break; } } + catch (const octave::exit_exception&) + { + // Catch and rethrow otherwise the (...) case will prevent + // us from exiting. + + throw; + } catch (const std::bad_alloc&) { recover_from_exception (); @@ -1004,6 +1027,26 @@ namespace octave std::cerr << "error: out of memory -- trying to return to prompt" << std::endl; } + catch (const std::exception& e) + { + recover_from_exception (); + + const char *msg = e.what (); + + if (msg) + { + std::cerr << "error: caught std::exception: " << msg + << std::endl; + std::cerr << "error: trying to return to prompt" << std::endl; + } + } + catch (...) + { + recover_from_exception (); + + std::cerr << "error: caught unknown exception -- trying to return to prompt" + << std::endl; + } #if defined (DBSTOP_NANINF) if (Vdebug_on_naninf) @@ -1056,7 +1099,7 @@ namespace octave OCTAVE_IGNORE_EXCEPTION (const octave::exit_exception&) \ OCTAVE_IGNORE_EXCEPTION (const octave::interrupt_exception&) \ OCTAVE_IGNORE_EXCEPTION (const octave::execution_exception&) \ - OCTAVE_IGNORE_EXCEPTION (const std::bad_alloc&) \ + OCTAVE_IGNORE_EXCEPTION (const std::exception&) \ } \ while (0)