From fdab090652b87dc096797021b05c667f94f61d95 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 18 Aug 2009 21:57:08 +0200 Subject: [PATCH] Implementing the new exception handing system in the core eval loops. --- source/continuations.cc | 2 +- source/eval_non_interactive.cc | 43 +++++++++++++++++++++++++++++++++++++++++- source/shapesexceptions.h | 1 + 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/source/continuations.cc b/source/continuations.cc index 56c02542..be622ed7 100644 --- a/source/continuations.cc +++ b/source/continuations.cc @@ -421,7 +421,7 @@ Kernel::DefaultErrorContinuation::~DefaultErrorContinuation( ) void Kernel::DefaultErrorContinuation::takeValue( const RefCountPtr< const Lang::Value > & val, Kernel::EvalState * evalState, bool dummy ) const { - throw Exceptions::UncaughtException( Helpers::down_cast_ContinuationArgument< const Lang::Exception >( val, this ) ); + throw Exceptions::UncaughtError( Helpers::down_cast_ContinuationArgument< const Lang::Exception >( val, this ) ); } Kernel::ContRef diff --git a/source/eval_non_interactive.cc b/source/eval_non_interactive.cc index cbb61ac3..b72c3424 100644 --- a/source/eval_non_interactive.cc +++ b/source/eval_non_interactive.cc @@ -43,6 +43,7 @@ nonInteractiveEvaluation( Kernel::WarmCatalog::ShipoutList & documents, SplitMod Kernel::ContRef( new Kernel::ExitContinuation( & done, Ast::theProgram->loc( ) ) ), Ast::theProgram->loc( ) ) ) ); + restart: try { while( ! done ) @@ -77,6 +78,26 @@ nonInteractiveEvaluation( Kernel::WarmCatalog::ShipoutList & documents, SplitMod & evalState ); goto restart; } + catch( const Exceptions::UncaughtError & uncaught ) + { + const Lang::Exception & ball = *uncaught.ball( ); + std::cout.flush( ); + if( Interaction::debugBacktrace ) + { + ball.cont( )->backTrace( std::cerr ); + } + + if( ! ball.loc( ).isUnknown( ) ) + { + std::cerr << ball.loc( ) << Exceptions::Exception::locsep ; + } + else + { + std::cerr << ball.cont( )->traceLoc( ) << Exceptions::Exception::locsep ; + } + ball.show( std::cerr ); + abortProcedure( ball.exitCode( ) ); + } catch( const Exceptions::Exception & ball ) { std::cout.flush( ); @@ -85,7 +106,7 @@ nonInteractiveEvaluation( Kernel::WarmCatalog::ShipoutList & documents, SplitMod evalState.cont_->backTrace( std::cerr ); } - Exceptions::RuntimeError & rerr = dynamic_cast< Exceptions::RuntimeError & >( ball ); + const Exceptions::RuntimeError & rerr = dynamic_cast< const Exceptions::RuntimeError & >( ball ); if( & rerr != 0 && ! rerr.getLoc( ).isUnknown( ) ) { std::cerr << rerr.getLoc( ) << Exceptions::Exception::locsep ; @@ -145,6 +166,26 @@ nonInteractiveEvaluation( Kernel::WarmCatalog::ShipoutList & documents, SplitMod ball.display( std::cerr ); abortProcedure( ball.exitCode( ) ); } + catch( const Exceptions::UncaughtError & uncaught ) + { + const Lang::Exception & ball = *uncaught.ball( ); + std::cout.flush( ); + if( Interaction::debugBacktrace ) + { + ball.cont( )->backTrace( std::cerr ); + } + + if( ! ball.loc( ).isUnknown( ) ) + { + std::cerr << ball.loc( ) << Exceptions::Exception::locsep ; + } + else + { + std::cerr << ball.cont( )->traceLoc( ) << Exceptions::Exception::locsep ; + } + ball.show( std::cerr ); + abortProcedure( ball.exitCode( ) ); + } catch( const Exceptions::Exception & ball ) { std::cout.flush( ); diff --git a/source/shapesexceptions.h b/source/shapesexceptions.h index f6377d7d..4a76e813 100644 --- a/source/shapesexceptions.h +++ b/source/shapesexceptions.h @@ -316,6 +316,7 @@ namespace Shapes virtual ~UncaughtError( ); virtual void display( std::ostream & os ) const; virtual Interaction::ExitCode exitCode( ) const; + const RefCountPtr< const Lang::Exception > & ball( ) const { return ball_; } }; class UserError : public CatchableError -- 2.11.4.GIT