+ void Interpreter::CatchInterpreterException( const InterpreterException& e )
+ {
+ if (GetExecuter()->GetNoErrorMode())
+ {
+ bbtkWarning("ERROR :"<<e.GetErrorMessage()
+ <<" ("<<e.GetScriptFile()<<":"<<e.GetScriptLine()
+ <<" skipped");
+
+ return;
+ }
+ if (mThrow)
+ {
+ if (e.GetErrorMessage()!="break")
+ {
+ mStatus = Interpreter_ERROR;
+ CloseAllFiles();
+ }
+ throw InterpreterException(e);
+ }
+ else
+ {
+ std::stringstream mess;
+ mess << "* ERROR : "<<e.GetErrorMessage()<<std::endl;
+ if (e.IsInScriptFile())
+ {
+ mess << "* FILE : \""<<e.GetScriptFile()<<"\""<<std::endl;
+ mess << "* LINE : "<<e.GetScriptLine()<<std::endl;
+ }
+ CloseAllFiles();
+ std::cerr << mess.str();
+ }
+ }
+ //=======================================================================
+
+ //=======================================================================
+ void Interpreter::CatchBbtkException( const bbtk::Exception& e )
+ {
+ if (GetExecuter()->GetNoErrorMode())
+ {
+ std::string file("?");
+ int line = 0;
+ if (mFileName.size()) {
+ file = mFileName.back();
+ line = mLine.back();
+ }
+ bbtkWarning("ERROR '"<<e.GetErrorMessage()
+ <<"' ("<<file<<":"<<line<<") skipped");
+
+ return;
+ }
+ mStatus = Interpreter_ERROR;
+ if (mThrow)
+ {
+ bool in_script = false;
+ std::string file("");
+ int line = 0;
+ if (mFileName.size()) {
+ std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
+ if (fs!=0) in_script = true;
+ file = mFileName.back();
+ line = mLine.back();
+ }
+ if (e.GetErrorMessage()!="break")
+ CloseAllFiles();
+ throw InterpreterException(e,in_script,file,line);
+ }
+ else
+ {
+ std::stringstream mess;
+ mess << "* ERROR : "<<e.GetErrorMessage()<<std::endl;
+ if (mFileName.size()) {
+ mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
+ mess << "* LINE : "<<mLine.back()<<std::endl;
+ }
+ CloseAllFiles();
+ std::cerr << mess.str();
+ }
+ }
+ //=======================================================================
+
+ //=======================================================================
+ void Interpreter::CatchStdException( const std::exception& e )
+ {
+ if (GetExecuter()->GetNoErrorMode())
+ {
+ std::string file("?");
+ int line = 0;
+ if (mFileName.size()) {
+ file = mFileName.back();
+ line = mLine.back();
+ }
+ bbtkWarning("ERROR '"<<e.what()
+ <<"' ("<<file<<":"<<line<<") skipped");
+
+ return;
+ }
+ mStatus = Interpreter_ERROR;
+ if (mThrow)
+ {
+ bool in_script = false;
+ std::string file("");
+ int line = 0;
+ if (mFileName.size()) {
+ std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
+ if (fs!=0) in_script = true;
+ file = mFileName.back();
+ line = mLine.back();
+ }
+ CloseAllFiles();
+ throw InterpreterException(e.what(),in_script,file,line);
+ }
+ else
+ {
+ std::stringstream mess;
+ mess << "* ERROR : "<<e.what()<<std::endl;
+ if (mFileName.size()) {
+ mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
+ mess << "* LINE : "<<mLine.back()<<std::endl;
+ }
+ CloseAllFiles();
+ std::cerr << mess.str();
+ }
+ }
+ //=======================================================================
+
+ //=======================================================================
+ void Interpreter::CatchUnknownException()
+ {
+ if (GetExecuter()->GetNoErrorMode())
+ {
+ std::string file("?");
+ int line = 0;
+ if (mFileName.size()) {
+ file = mFileName.back();
+ line = mLine.back();
+ }
+ bbtkWarning("UNDEFINED ERROR "
+ <<"("<<file<<":"<<line<<") skipped");
+ return;
+ }
+ mStatus = Interpreter_ERROR;
+ if (mThrow)
+ {
+ bool in_script = false;
+ std::string file("");
+ int line = 0;
+ if (mFileName.size()) {
+ std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
+ if (fs!=0) in_script = true;
+ file = mFileName.back();
+ line = mLine.back();
+ }
+ CloseAllFiles();
+ throw InterpreterException("Unknown exception caught",
+ in_script,file,line);
+ }
+ else
+ {
+ std::stringstream mess;
+ mess << "* UNDEFINED ERROR (not a bbtk nor a std exception)"
+ << std::endl;
+ if (mFileName.size()) {
+ mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
+ mess << "* LINE : "<<mLine.back()<<std::endl;
+ }
+ CloseAllFiles();
+ std::cerr << mess.str();
+ }
+ }
+ //=======================================================================
+
+ //=======================================================================
+
+#define CATCH_MACRO \
+ catch (InterpreterException e) \
+ { \
+ CatchInterpreterException(e); \
+ } \
+ catch (bbtk::Exception e) \
+ { \
+ CatchBbtkException(e); \
+ } \
+ catch (std::exception& e) \
+ { \
+ CatchStdException(e); \
+ } \
+ catch (...) \
+ { \
+ CatchUnknownException(); \
+ }
+ //=======================================================================
+
+
+ //=======================================================================
+ Interpreter::ExitStatus Interpreter::InterpretFile( const std::string& filename, bool source )