Handle specific exception in implementation of from_json for smtk::task::Task
The current implementation of task deserializer is the following:
void from_json(const nlohmann::json& jj, smtk::task::Task::Ptr& task)
{
try
{
auto& helper = json::Helper::instance();
auto managers = helper.managers();
auto& taskManager = helper.taskManager();
auto taskType = jj.at("type").get<std::string>();
task = taskManager.taskInstances().createFromName(
taskType, const_cast<nlohmann::json&>(jj), managers);
if (jj.contains("active") && jj.at("active").get<bool>())
{
helper.setActiveSerializedTask(task.get());
}
}
catch (std::exception& e)
{
smtkErrorMacro(
smtk::io::Logger::instance(), "Could not deserialize task (" << e.what() << ").");
}
}
If my custom task implementation throws any exception, creation of the task will fail result in a nullptr for the task and then a crash. The catch block here should probably be more specific about the types of exceptions that will be handled here and all other serializer/deserializer implementation should do the same.
Edited by jwilson1881