Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor LocalDomainError and SimulationError for improved exception handling. #92

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 19 additions & 33 deletions Source/moja.flint/src/spatialtiledlocaldomaincontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,25 +792,11 @@ bool SpatialTiledLocalDomainController::runCellSpinUp(std::shared_ptr<StatsUnitR
blockStatsUnit->_unitsProcessed++;
return true;
} catch (const flint::SimulationError& e) {
std::string details = *(boost::get_error_info<Details>(e));
std::string libraryName = *(boost::get_error_info<LibraryName>(e));
std::string moduleName = *(boost::get_error_info<ModuleName>(e));
const int* errorCode = boost::get_error_info<ErrorCode>(e);
_spatiallocationinfo->_errorCode = *errorCode;
_spatiallocationinfo->_library = libraryName;
_spatiallocationinfo->_module = moduleName;
_spatiallocationinfo->_message = details;
std::string details = _handleFLINTException(e); // Template function call
_spinupNotificationCenter.postNotification(moja::signals::Error, details);
return true;
} catch (const flint::LocalDomainError& e) {
std::string details = *(boost::get_error_info<Details>(e));
std::string libraryName = *(boost::get_error_info<LibraryName>(e));
std::string moduleName = *(boost::get_error_info<ModuleName>(e));
const int* errorCode = boost::get_error_info<ErrorCode>(e);
_spatiallocationinfo->_errorCode = *errorCode;
_spatiallocationinfo->_library = libraryName;
_spatiallocationinfo->_module = moduleName;
_spatiallocationinfo->_message = details;
std::string details = _handleFLINTException(e); // Template function call
_spinupNotificationCenter.postNotification(moja::signals::Error, details);
} catch (flint::VariableNotFoundException& e) {
std::string str =
Expand Down Expand Up @@ -844,6 +830,20 @@ bool SpatialTiledLocalDomainController::runCellSpinUp(std::shared_ptr<StatsUnitR
}
return true;
}
// Here this template function will handle all the string and spatiallocationinfo for
// both the LocalDomainError and SimulationError. From lines 794-816 and 933-959.
template <typename FlintExceptionType&>
std::string _handleFLINTException(const FlintExceptionType& e) {
std::string details = *(boost::get_error_info<Details>(e));
std::string libraryName = *(boost::get_error_info<LibraryName>(e));
std::string moduleName = *(boost::get_error_info<ModuleName>(e));
const int* errorCode = boost::get_error_info<ErrorCode>(e);
_spatiallocationinfo->_errorCode = *errorCode;
_spatiallocationinfo->_library = libraryName;
_spatiallocationinfo->_module = moduleName;
_spatiallocationinfo->_message = details;
return details;
}

// --------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -929,32 +929,18 @@ bool SpatialTiledLocalDomainController::runCell(std::shared_ptr<StatsUnitRecord>
}

}
// This error is recoverable, retunr true for success
// This error is recoverable, return true for success
catch (const flint::SimulationError& e) {
// This error is recoverable, drop cell and continue simulation
std::string details = *(boost::get_error_info<Details>(e));
std::string libraryName = *(boost::get_error_info<LibraryName>(e));
std::string moduleName = *(boost::get_error_info<ModuleName>(e));
const int* errorCode = boost::get_error_info<ErrorCode>(e);
_spatiallocationinfo->_errorCode = *errorCode;
_spatiallocationinfo->_library = libraryName;
_spatiallocationinfo->_module = moduleName;
_spatiallocationinfo->_message = details;
std::string details = _handleFLINTException(e); // Template function call
_notificationCenter.postNotification(moja::signals::Error, details);
blockStatsUnit->_unitsNotProcessed++;
blockStatsUnit->_unitsWithError++;
return true;
}
// All other catches are failures for the localdomain, return false!
catch (const flint::LocalDomainError& e) {
std::string details = *(boost::get_error_info<Details>(e));
std::string libraryName = *(boost::get_error_info<LibraryName>(e));
std::string moduleName = *(boost::get_error_info<ModuleName>(e));
const int* errorCode = boost::get_error_info<ErrorCode>(e);
_spatiallocationinfo->_errorCode = *errorCode;
_spatiallocationinfo->_library = libraryName;
_spatiallocationinfo->_module = moduleName;
_spatiallocationinfo->_message = details;
std::string details = _handleFLINTException(e); // Template function call
_notificationCenter.postNotification(moja::signals::Error, details);
} catch (flint::VariableNotFoundException& e) {
std::string str = ((boost::format("Variable not found: %1%") % *(boost::get_error_info<VariableName>(e))).str());
Expand Down