Skip to content

Commit 703737f

Browse files
committed
Fixing access specifiers on exceptions, removed unused exception
1 parent 9395a5d commit 703737f

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

include/libdbc/exceptions/error.hpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,19 @@
66
namespace libdbc {
77

88
class exception : public std::exception {
9+
public:
910
const char * what() const throw() {
1011
return "libdbc exception occurred";
1112
}
1213
};
1314

1415
class validity_error : public exception {
16+
public:
1517
const char * what() const throw() {
16-
return "Invalid DBC file...";
18+
return "Invalid DBC file";
1719
}
1820
};
1921

20-
class header_error : public validity_error {
21-
header_error(const char* line, const char* expected, const char * file) :
22-
line(line), expected(expected), file(file) {}
23-
24-
const char * what() const throw() {
25-
std::ostringstream os;
26-
os << "Issue with the header line ( " << line << " ) in file ( ";
27-
os << file << " ). Expected to find: " << expected;
28-
return os.str().c_str();
29-
}
30-
31-
private:
32-
const char * line;
33-
const char * expected;
34-
const char * file;
35-
};
36-
3722
} // libdbc
3823

3924
#endif // __ERROR_HPP__

test/test_dbc.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ TEST_CASE("Testing dbc file loading error issues", "[fileio][error]") {
2222
// very well standardized for now we ignore this type of error.
2323
CHECK_NOTHROW(parser->parse_file(MISSING_NEW_SYMBOLS_DBC_FILE));
2424
}
25+
26+
SECTION("Verify that what() method is accessible for all exceptions", "[error]")
27+
{
28+
auto generic_error = libdbc::exception();
29+
REQUIRE(generic_error.what() == "libdbc exception occurred");
30+
31+
auto validity_check = libdbc::validity_error();
32+
REQUIRE(validity_check.what() == "Invalid DBC file");
33+
}
2534
}
2635

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

0 commit comments

Comments
 (0)