Program: bbtk
Module: $RCSfile: bbtkInterpreter.cxx,v $ $
Language: C++
- Date: $Date: 2008/03/21 11:44:37 $
- Version: $Revision: 1.51 $
+ Date: $Date: 2008/03/21 14:59:39 $
+ Version: $Revision: 1.52 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
//=======================================================================
+ InterpreterError::InterpreterError( const std::string& message,
+ bool in_script_file,
+ const std::string& script_file,
+ int script_line
+ )
+ : Exception("Interpreter",0,message),
+ mInScriptFile(in_script_file),
+ mScriptFile(script_file),
+ mScriptLine(script_line)
+ {
+ }
+ InterpreterError::InterpreterError( const Exception& excep,
+ bool in_script_file,
+ const std::string& script_file,
+ int script_line
+ )
+ : Exception(excep),
+ mInScriptFile(in_script_file),
+ mScriptFile(script_file),
+ mScriptLine(script_line)
+ {
+ }
+ //=======================================================================
+ void Interpreter::CatchBbtkException( const bbtk::Exception& e )
+ {
+ 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();
+ }
+ throw InterpreterError(e,in_script,file,line);
+ }
+ else
+ {
+ std::stringstream mess;
+ mess << "* ERROR : "<<e.GetMessage()<<std::endl;
+ if (mFileName.size()) {
+ mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
+ mess << "* LINE : "<<mLine.back()<<std::endl;
+ }
+ std::cerr << mess.str();
+ }
+ }
+ //=======================================================================
+
+ //=======================================================================
+ void Interpreter::CatchStdException( const std::exception& e )
+ {
+ 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();
+ }
+ throw InterpreterError(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;
+ }
+ std::cerr << mess.str();
+ }
+ }
+ //=======================================================================
+
+ //=======================================================================
+ void Interpreter::CatchUnknownException()
+ {
+ 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();
+ }
+ throw InterpreterError("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;
+ }
+ std::cerr << mess.str();
+ }
+ }
+ //=======================================================================
+
+ //=======================================================================
+
+#define CATCH_MACRO \
+ catch (QuitException e) \
+ { \
+ status = Interpreter_QUIT; \
+ if (mThrow) throw QuitException(); \
+ } \
+ catch (bbtk::Exception e) \
+ { \
+ status = Interpreter_ERROR; \
+ CatchBbtkException(e); \
+ } \
+ catch (std::exception& e) \
+ { \
+ status = Interpreter_ERROR; \
+ CatchStdException(e); \
+ } \
+ catch (...) \
+ { \
+ status = Interpreter_ERROR; \
+ CatchUnknownException(); \
+ }
+ //=======================================================================
+
+
//=======================================================================
/**
*
ExitStatus status = Interpreter_OK;
-
try
{
SwitchToFile(filename);
CloseCurrentFile();
}
}
- catch (QuitException e)
- {
- status = Interpreter_QUIT;
- if (mThrow) throw QuitException();
- }
- catch (bbtk::Exception e)
- {
- std::stringstream mess;
- mess << "* ERROR : "<<e.GetMessage()<<std::endl;
- if (mFileName.size()) {
- mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
- mess << "* LINE : "<<mLine.back()<<std::endl;
- }
- status = Interpreter_ERROR;
- if (mThrow)
- throw bbtk::Exception("Interpreter","",mess.str());
- else
- std::cerr << mess.str();
-
- }
- catch (std::exception& e)
- {
- std::stringstream mess;
- mess << "* ERROR : "<<e.what()<<" (not in bbtk)"<<std::endl;
- if (mFileName.size()) {
- mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
- mess << "* LINE : "<<mLine.back()<<std::endl;
- }
- status = Interpreter_ERROR;
- if (mThrow)
- throw bbtk::Exception("Interpreter","",mess.str());
- else
- std::cerr << mess.str();
- }
- catch (...)
- {
- 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;
- }
- status = Interpreter_ERROR;
- if (mThrow)
- throw bbtk::Exception("Interpreter","",mess.str());
- else
- std::cerr << mess.str();
- }
+ CATCH_MACRO;
CloseAllFiles();
bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
CloseCurrentFile();
}
}
- catch (QuitException e)
- {
- status = Interpreter_QUIT;
- }
- catch (bbtk::Exception e)
- {
- std::cerr << "* ERROR : "<<e.GetMessage()<<std::endl;
- if (mFileName.size())
- {
- std::cerr << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
- std::cerr << "* LINE : "<<mLine.back()<<std::endl;
- }
- status = Interpreter_ERROR;
- }
- catch (std::exception& e)
- {
- std::cerr << "* ERROR : "<<e.what()<<" (not in bbtk)"<<std::endl;
- if (mFileName.size())
- {
- std::cerr << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
- std::cerr << "* LINE : "<<mLine.back()<<std::endl;
- }
- status = Interpreter_ERROR;
- }
- catch (...)
- {
- std::cerr
- << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
- if (mFileName.size())
- {
- std::cerr << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
- std::cerr << "* LINE : "<<mLine.back()<<std::endl;
- }
- status = Interpreter_ERROR;
- }
+ CATCH_MACRO;
CloseAllFiles();
bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretBuffer()"<<std::endl);
bool insideComment = false;
InterpretLine(line, insideComment);
}
- catch (QuitException e)
+ CATCH_MACRO;
+ /*
+ catch (QuitException e)
{
status = Interpreter_QUIT;
}
<< "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
status = Interpreter_ERROR;
}
-
+ */
bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretLine()"
<<std::endl);
mFileName.push_back(fullPathScriptName);
mIncludeFileName.push_back(includeScriptName);
mLine.push_back(0);
+
return;
}