Skip to content

Commit

Permalink
Move MEF specific Error classes to mef namespace
Browse files Browse the repository at this point in the history
This is needed to further refine the data passed to exceptions.
The MEF specific validation errors should be used
instead of generic InvalidArgument error class.

Issue #219
  • Loading branch information
rakhimov committed Oct 15, 2017
1 parent a5af9c0 commit d35b831
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion gui/eventdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void EventDialog::validate()
tr("The event with name '%1' already exists.").arg(name));
return;
}
} catch (UndefinedElement &) {}
} catch (mef::UndefinedElement &) {}

if (!tabFormula->isHidden() && hasFormulaArg(name)) {
m_errorBar->showMessage(
Expand Down
2 changes: 1 addition & 1 deletion gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ mef::FormulaPtr MainWindow::extract(const EventDialog &dialog)
for (const std::string &arg : dialog.arguments()) {
try {
formula->AddArgument(m_model->GetEvent(arg));
} catch (UndefinedElement &) {
} catch (mef::UndefinedElement &) {
auto argEvent = std::make_unique<mef::BasicEvent>(arg);
argEvent->AddAttribute({"flavor", "undeveloped", ""});
formula->AddArgument(argEvent.get());
Expand Down
54 changes: 29 additions & 25 deletions src/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,39 @@ class Error : virtual public std::exception, virtual public boost::exception {
std::string thrown_; ///< The message to throw with the prefix.
};

/// For input/output related errors.
struct IOError : public Error {
using Error::Error;
};

/// This error class can be used
/// to indicate unacceptable arguments.
struct InvalidArgument : public Error {
using Error::Error;
};

/// Signals internal logic errors,
/// for example, pre-condition failure
/// or use of functionality in ways not designed to.
struct LogicError : public Error {
using Error::Error;
};

/// This error can be used to indicate
/// that call for a function or operation is not legal.
/// For example, a derived class can make illegal
/// the call of the virtual function of the base class.
struct IllegalOperation : public Error {
using Error::Error;
};

/// The error in analysis settings.
struct SettingsError : public Error {
using Error::Error;
};

namespace mef { // MEF specific errors.

/// For validating input parameters or user arguments.
struct ValidationError : public Error {
using Error::Error;
Expand All @@ -114,31 +142,7 @@ struct CycleError : public ValidationError {
using ValidationError::ValidationError;
};

/// For input/output related errors.
struct IOError : public Error {
using Error::Error;
};

/// This error class can be used
/// to indicate unacceptable arguments.
struct InvalidArgument : public Error {
using Error::Error;
};

/// Signals internal logic errors,
/// for example, pre-condition failure
/// or use of functionality in ways not designed to.
struct LogicError : public Error {
using Error::Error;
};

/// This error can be used to indicate
/// that call for a function or operation is not legal.
/// For example, a derived class can make illegal
/// the call of the virtual function of the base class.
struct IllegalOperation : public Error {
using Error::Error;
};
} // namespace mef

} // namespace scram

Expand Down
6 changes: 1 addition & 5 deletions src/xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ namespace scram {

namespace xml {

class Element;

} // namespace xml

namespace xml {
using mef::ValidationError; ///< @todo Create XML specific exception classes.

using string_view = boost::string_ref; ///< Non-owning, immutable string view.

Expand Down
4 changes: 2 additions & 2 deletions tests/config_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ TEST(ConfigTest, IOError) {
// Test with XML content validation issues.
TEST(ConfigTest, ValidationError) {
std::string config_file = "./share/scram/input/fta/invalid_configuration.xml";
ASSERT_THROW(Config config(config_file), ValidationError);
ASSERT_THROW(Config config(config_file), xml::ValidationError);
}

// Test with XML content numerical issues.
TEST(ConfigTest, NumericalErrors) {
std::string config_file = "./share/scram/input/fta/int_overflow_config.xml";
ASSERT_THROW(Config config(config_file), ValidationError);
ASSERT_THROW(Config config(config_file), xml::ValidationError);
}

// Tests all settings with one file.
Expand Down

0 comments on commit d35b831

Please sign in to comment.