Skip to content

Commit a61cc21

Browse files
committed
Switch to custom exceptions
1 parent 453540e commit a61cc21

File tree

4 files changed

+44
-24
lines changed

4 files changed

+44
-24
lines changed

source/adios2/common/ADIOSTypes.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,34 @@ std::string ToString(const Dims &dims);
359359
std::string ToString(const Box<Dims> &box);
360360
std::string ToString(const MemorySpace value);
361361

362+
// Derived exception class for specific errors
363+
class PluginLoadFailure : public std::runtime_error
364+
{
365+
public:
366+
PluginLoadFailure(const std::string &msg, const std::string &Library, const std::string &Name)
367+
: runtime_error(msg), m_PluginLibrary(Library), m_PluginName(Name)
368+
{
369+
}
370+
371+
std::string m_PluginLibrary;
372+
std::string m_PluginName;
373+
374+
private:
375+
};
376+
377+
class MissingOperatorFailure : public std::invalid_argument
378+
{
379+
public:
380+
MissingOperatorFailure(const std::string &msg, const std::string &Operator)
381+
: invalid_argument(msg), m_Operator(Operator)
382+
{
383+
}
384+
385+
std::string m_Operator;
386+
387+
private:
388+
};
389+
362390
/** UserOptions holds all user options from ~/.config/adios2/adios2.yaml */
363391
struct UserOptions
364392
{

source/adios2/operator/OperatorFactory.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,11 @@ std::shared_ptr<Operator> MakeOperator(const std::string &type, const Params &pa
182182

183183
if (ret == nullptr)
184184
{
185-
helper::Throw<std::invalid_argument>("Operator", "OperatorFactory", "MakeOperator",
186-
"ADIOS2 didn't compile with " + typeLowerCase +
187-
" library, operator not added");
185+
auto m = MakeMessage("Operator", "OperatorFactory", "MakeOperator",
186+
"ADIOS2 didn't compile with " + typeLowerCase +
187+
" library, operator not added",
188+
-1, helper::LogMode::EXCEPTION);
189+
throw MissingOperatorFailure(m, typeLowerCase);
188190
}
189191

190192
return ret;

source/adios2/operator/plugin/PluginOperator.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ void PluginOperator::PluginInit(const std::string &pluginName, const std::string
8282
}
8383
catch (...)
8484
{
85-
helper::Throw<std::runtime_error>("Plugins", "PluginOperator", "PluginInit",
86-
"Failed to load library \"" + pluginLibrary +
87-
"\" looking for plugin \"" + pluginName + "\"");
85+
auto m = MakeMessage("Plugins", "PluginOperator", "PluginInit",
86+
"Failed to load library " + m_PluginLibrary + " looking for plugin " +
87+
m_PluginName,
88+
-1, helper::LogMode::EXCEPTION);
89+
throw PluginLoadFailure(m, pluginLibrary, pluginName);
8890
}
8991
m_Impl->m_HandleCreate = pluginManager.GetOperatorCreateFun(pluginName);
9092
m_Impl->m_HandleDestroy = pluginManager.GetOperatorDestroyFun(pluginName);

source/utils/bpls/bpls.cpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,27 +1026,15 @@ int doList_operators(core::Engine *fp, core::IO *io)
10261026
OpStrings.insert(op->m_TypeString);
10271027
}
10281028
}
1029-
catch (std::invalid_argument const &ex)
1029+
catch (MissingOperatorFailure const &ex)
10301030
{
1031-
// if we didn't compile with the operator, the above with throw. Parse the text
1032-
std::string text = ex.what();
1033-
size_t start = text.find("compile with ") + 13;
1034-
size_t end = text.substr(start).find(' ');
1035-
std::string op = text.substr(start, end);
1036-
OpStrings.insert(op);
1031+
// we didn't compile with the operator used
1032+
OpStrings.insert(ex.m_Operator);
10371033
}
1038-
catch (std::runtime_error const &ex)
1034+
catch (PluginLoadFailure const &ex)
10391035
{
1040-
// plugin operator we didn't find Parse the text
1041-
std::string text = ex.what();
1042-
size_t libstart = text.find("library \"") + 9;
1043-
size_t libend = text.substr(libstart).find('"');
1044-
std::string lib = text.substr(libstart, libend);
1045-
std::string rem = text.substr(libstart + libend + 1);
1046-
size_t opstart = rem.find('"') + 1;
1047-
size_t opend = rem.substr(opstart).find('"');
1048-
std::string op = rem.substr(opstart, opend);
1049-
OpStrings.insert(lib + "(" + op + ")");
1036+
// plugin operator we didn't find
1037+
OpStrings.insert(ex.m_PluginLibrary + "(" + ex.m_PluginName + ")");
10501038
}
10511039
}
10521040
}

0 commit comments

Comments
 (0)