Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 3 additions & 18 deletions include/libdbc/exceptions/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,19 @@
namespace libdbc {

class exception : public std::exception {
public:
const char * what() const throw() {
return "libdbc exception occurred";
}
};

class validity_error : public exception {
public:
const char * what() const throw() {
return "Invalid DBC file...";
return "Invalid DBC file";
}
};

class header_error : public validity_error {
header_error(const char* line, const char* expected, const char * file) :
line(line), expected(expected), file(file) {}

const char * what() const throw() {
std::ostringstream os;
os << "Issue with the header line ( " << line << " ) in file ( ";
os << file << " ). Expected to find: " << expected;
return os.str().c_str();
}

private:
const char * line;
const char * expected;
const char * file;
};

} // libdbc

#endif // __ERROR_HPP__
9 changes: 9 additions & 0 deletions test/test_dbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ TEST_CASE("Testing dbc file loading error issues", "[fileio][error]") {
// very well standardized for now we ignore this type of error.
CHECK_NOTHROW(parser->parse_file(MISSING_NEW_SYMBOLS_DBC_FILE));
}

SECTION("Verify that what() method is accessible for all exceptions", "[error]")
{
auto generic_error = libdbc::exception();
REQUIRE(generic_error.what() == "libdbc exception occurred");

auto validity_check = libdbc::validity_error();
REQUIRE(validity_check.what() == "Invalid DBC file");
}
}

TEST_CASE("Testing dbc file loading", "[fileio]") {
Expand Down