Skip to content
Snippets Groups Projects
Commit 3140c83e authored by Julien Michel's avatar Julien Michel Committed by Antoine Regimbeau
Browse files

Merge branch '1638-no-catch-when-testenv-on' into 'develop'

Resolve "Debug mode without try {} catch(...) in otbApplicationLauncherCommandLine"

Closes #1638

See merge request !145
parent c029979b
No related branches found
No related tags found
No related merge requests found
......@@ -172,6 +172,12 @@ private:
CommandLineLauncher(const CommandLineLauncher &); //purposely not implemented
void operator =(const CommandLineLauncher&); //purposely not implemented
/**
* Actually launch the process and write outputs, without catching exceptions.
*/
bool ExecuteAndWriteOutputNoCatch();
std::string m_Path;
Application::Pointer m_Application;
......
......@@ -137,68 +137,79 @@ bool CommandLineLauncher::Execute()
return false;
}
bool CommandLineLauncher::ExecuteAndWriteOutput()
bool CommandLineLauncher::ExecuteAndWriteOutputNoCatch()
{
try
{
if (this->BeforeExecute() == false)
{
if (this->BeforeExecute() == false)
{
return false;
}
}
if( m_Application->ExecuteAndWriteOutput() == 0 )
{
{
this->DisplayOutputParameters();
}
}
else
{
{
return false;
}
return true;
}
bool CommandLineLauncher::ExecuteAndWriteOutput()
{
// If testenv is used, do not catch exceptions
if (m_Parser->IsAttributExists("-testenv", m_VExpression) == true)
{
return ExecuteAndWriteOutputNoCatch();
}
}
catch(otb::ApplicationException& err)
{
else
{
try
{
return ExecuteAndWriteOutputNoCatch();
}
catch(otb::ApplicationException& err)
{
// These are thrown with otbAppLogFATAL, a macro which logs a user
// friendly error message before throwing. So log exception details only
// in debug.
m_Application->GetLogger()->Debug("Caught otb::ApplicationException during application execution:\n");
m_Application->GetLogger()->Debug(string(err.what()) + "\n");
return false;
}
catch(otb::ImageFileReaderException& err)
{
}
catch(otb::ImageFileReaderException& err)
{
m_Application->GetLogger()->Debug("Caught otb::ImageFileReaderException during application execution:\n");
m_Application->GetLogger()->Debug(string(err.what()) + "\n");
m_Application->GetLogger()->Fatal(string("Cannot open image ") + err.m_Filename + string(". ") + err.GetDescription() + string("\n"));
return false;
}
catch(itk::ExceptionObject& err)
{
m_Application->GetLogger()->Debug("Caught itk::ExceptionObject during application execution:\n");
m_Application->GetLogger()->Debug(string(err.what()) + "\n");
m_Application->GetLogger()->Fatal(string(err.GetDescription()) + "\n");
return false;
}
catch(std::exception& err)
{
m_Application->GetLogger()->Fatal(std::string("Caught std::exception during application execution: ") + err.what() + "\n");
return false;
}
catch(...)
{
m_Application->GetLogger()->Fatal("Caught unknown exception during application execution.\n");
return false;
}
return true;
}
catch(itk::ExceptionObject& err)
{
m_Application->GetLogger()->Debug("Caught itk::ExceptionObject during application execution:\n");
m_Application->GetLogger()->Debug(string(err.what()) + "\n");
m_Application->GetLogger()->Fatal(string(err.GetDescription()) + "\n");
return false;
}
catch(std::exception& err)
{
m_Application->GetLogger()->Fatal(std::string("Caught std::exception during application execution: ") + err.what() + "\n");
return false;
}
catch(...)
{
m_Application->GetLogger()->Fatal("Caught unknown exception during application execution.\n");
return false;
}
}
}
bool CommandLineLauncher::BeforeExecute()
{
if (m_Application.IsNull())
{
{
std::cerr << "ERROR: No loaded application." << std::endl;
return false;
}
}
// Check if there's keys in the expression if the application takes
// at least 1 mandatory parameter
......@@ -263,15 +274,15 @@ bool CommandLineLauncher::BeforeExecute()
ParamResultType result = this->LoadParameters();
if (result == MISSINGMANDATORYPARAMETER)
{
{
std::cerr << std::endl;
this->DisplayHelp();
return false;
}
}
else if (result != OKPARAM)
{
{
return false;
}
}
return true;
}
......@@ -365,22 +376,22 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters()
// Check for the progress report parameter
if (m_Parser->IsAttributExists("-progress", m_VExpression) == true)
{
{
std::vector<std::string> val = m_Parser->GetAttribut("-progress", m_VExpression);
if (val.size() == 1 && (val[0] == "1" || val[0] == "true"))
{
{
m_ReportProgress = true;
}
}
else if (val.size() == 1 && (val[0] == "0" || val[0] == "false"))
{
{
m_ReportProgress = false;
}
}
else
{
{
std::cerr << "ERROR: Invalid value for parameter -progress. It must be 0, 1, false or true." << std::endl;
return WRONGPARAMETERVALUE;
}
}
}
const std::vector<std::string> appKeyList = m_Application->GetParametersKeys(true);
// Loop over each parameter key declared in the application
......@@ -421,22 +432,22 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters()
m_Application->SetParameterStringList(paramKey, values);
}
else if (type == ParameterType_Choice ||
type == ParameterType_Float ||
type == ParameterType_Int ||
type == ParameterType_Radius ||
type == ParameterType_Directory ||
type == ParameterType_String ||
type == ParameterType_InputFilename ||
type == ParameterType_OutputFilename ||
type == ParameterType_ComplexInputImage ||
type == ParameterType_InputImage ||
type == ParameterType_OutputImage ||
type == ParameterType_ComplexOutputImage ||
type == ParameterType_InputVectorData ||
type == ParameterType_OutputVectorData ||
type == ParameterType_RAM ||
type == ParameterType_OutputProcessXML ||
type == ParameterType_Bool) // || type == ParameterType_InputProcessXML)
type == ParameterType_Float ||
type == ParameterType_Int ||
type == ParameterType_Radius ||
type == ParameterType_Directory ||
type == ParameterType_String ||
type == ParameterType_InputFilename ||
type == ParameterType_OutputFilename ||
type == ParameterType_ComplexInputImage ||
type == ParameterType_InputImage ||
type == ParameterType_OutputImage ||
type == ParameterType_ComplexOutputImage ||
type == ParameterType_InputVectorData ||
type == ParameterType_OutputVectorData ||
type == ParameterType_RAM ||
type == ParameterType_OutputProcessXML ||
type == ParameterType_Bool) // || type == ParameterType_InputProcessXML)
{
// Single value parameter
m_Application->SetParameterString(paramKey, values[0]);
......@@ -459,7 +470,7 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters()
{
std::cerr << "ERROR: Too many values for parameter -" <<
paramKey << " (expected 2 or 1, got " << values.size() << ")."
<< std::endl;
<< std::endl;
return INVALIDNUMBEROFVALUE;
}
}
......@@ -756,11 +767,11 @@ std::string CommandLineLauncher::DisplayParameterHelp(const Parameter::Pointer &
oss << "[";
for(unsigned int i=0; i<keys.size(); i++)
{
{
oss<<keys[i];
if( i != keys.size()-1 )
oss << "/";
}
}
oss << "]";
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment