-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing library specific exception
User code can catch it and do appropriate action. This allows the application code to distinguish between exceptions specific to fprops and other ones.
- Loading branch information
Showing
12 changed files
with
121 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include "fmt/format.h" | ||
#include <exception> | ||
|
||
namespace fprops { | ||
|
||
class Exception : public std::exception { | ||
public: | ||
template <typename... T> | ||
Exception(fmt::format_string<T...> format, T... args) : | ||
msg(fmt::format(format, std::forward<T>(args)...)) | ||
{ | ||
} | ||
|
||
/// Get the exception message | ||
[[nodiscard]] auto what() const noexcept -> const char * override; | ||
|
||
private: | ||
/// Error message | ||
std::string msg; | ||
}; | ||
|
||
} // namespace fprops |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "fprops/Exception.h" | ||
|
||
namespace fprops { | ||
|
||
auto | ||
Exception::what() const noexcept -> const char * | ||
{ | ||
return this->msg.c_str(); | ||
} | ||
|
||
} // namespace fprops |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include "fprops/Exception.h" | ||
|
||
/// Test that the `cmd` will throw `fprops::Exception` with message `msg` | ||
#define EXPECT_THROW_MSG(cmd, msg) \ | ||
try { \ | ||
cmd; \ | ||
FAIL(); \ | ||
} \ | ||
catch (Exception & e) { \ | ||
EXPECT_STREQ(e.what(), msg); \ | ||
} \ | ||
catch (...) { \ | ||
FAIL(); \ | ||
} | ||
|
||
#define EXPECT_THAT_THROW_MSG(cmd, matcher) \ | ||
try { \ | ||
cmd; \ | ||
FAIL(); \ | ||
} \ | ||
catch (Exception & e) { \ | ||
EXPECT_THAT(e.what(), matcher); \ | ||
} \ | ||
catch (...) { \ | ||
FAIL(); \ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.