diff --git a/Code/ApplicationEngine/otbWrapperApplication.cxx b/Code/ApplicationEngine/otbWrapperApplication.cxx index 651b609e0e256664d766086d341b7f87f5443974..b6677b42fe410d9c897ae84d1326b5cd11e6199c 100644 --- a/Code/ApplicationEngine/otbWrapperApplication.cxx +++ b/Code/ApplicationEngine/otbWrapperApplication.cxx @@ -108,48 +108,56 @@ void Application::UpdateParameters() this->DoUpdateParameters(); } -void Application::Execute() +bool Application::Execute() { + bool ret = true; + try { this->DoExecute(); } catch(std::exception& err) { + ret = false; otbAppLogFATAL(<<err.what()); } catch(...) { + ret = false; otbAppLogFATAL(<<"Unknown exception thrown."); } + + return ret; } void Application::ExecuteAndWriteOutput() { - this->Execute(); - std::vector<std::string> paramList = GetParametersKeys(true); - for (std::vector<std::string>::const_iterator it = paramList.begin(); - it != paramList.end(); - ++it) + if (this->Execute()) { - std::string key = *it; - if (GetParameterType(key) == ParameterType_OutputImage - && IsParameterEnabled(key) && HasValue(key) ) + std::vector<std::string> paramList = GetParametersKeys(true); + for (std::vector<std::string>::const_iterator it = paramList.begin(); + it != paramList.end(); + ++it) { - Parameter* param = GetParameterByKey(key); - OutputImageParameter* outputParam = dynamic_cast<OutputImageParameter*>(param); - outputParam->InitializeWriters(); - AddProcess(outputParam->GetWriter(),"Writer"); - outputParam->Write(); - } - else if (GetParameterType(key) == ParameterType_OutputVectorData - && IsParameterEnabled(key) && HasValue(key) ) - { - Parameter* param = GetParameterByKey(key); - OutputVectorDataParameter* outputParam = dynamic_cast<OutputVectorDataParameter*>(param); - outputParam->InitializeWriters(); - AddProcess(outputParam->GetWriter(),"Writer"); - outputParam->Write(); + std::string key = *it; + if (GetParameterType(key) == ParameterType_OutputImage + && IsParameterEnabled(key) && HasValue(key) ) + { + Parameter* param = GetParameterByKey(key); + OutputImageParameter* outputParam = dynamic_cast<OutputImageParameter*>(param); + outputParam->InitializeWriters(); + AddProcess(outputParam->GetWriter(),"Writer"); + outputParam->Write(); + } + else if (GetParameterType(key) == ParameterType_OutputVectorData + && IsParameterEnabled(key) && HasValue(key) ) + { + Parameter* param = GetParameterByKey(key); + OutputVectorDataParameter* outputParam = dynamic_cast<OutputVectorDataParameter*>(param); + outputParam->InitializeWriters(); + AddProcess(outputParam->GetWriter(),"Writer"); + outputParam->Write(); + } } } } diff --git a/Code/ApplicationEngine/otbWrapperApplication.h b/Code/ApplicationEngine/otbWrapperApplication.h index c636e4acca5095dc1493e9ff47795c2bcbbbb692..51c73651115c89c620873162dff791e2efeb0e5b 100644 --- a/Code/ApplicationEngine/otbWrapperApplication.h +++ b/Code/ApplicationEngine/otbWrapperApplication.h @@ -82,7 +82,7 @@ public: * * In other cases, the application must handle * the I/O (intermediary results for example) */ - void Execute(); + bool Execute(); /** Run the application, then writes all the output to disk * if they have an associated filename.