-
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.
Merge pull request #101 from AGH-Code-Industry/twarug/exceptions
Refactor Archimedes Exceptions
- Loading branch information
Showing
12 changed files
with
123 additions
and
55 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 |
---|---|---|
@@ -1,20 +1,61 @@ | ||
#pragma once | ||
|
||
#include <exception> | ||
#include <string> | ||
#include <source_location> | ||
|
||
#include "Logger.h" | ||
|
||
namespace arch { | ||
|
||
/// Base class for all exceptions in the project. | ||
/// Do not use this class directly, use derived classes instead. (@see InitException) | ||
/// | ||
class Exception: public std::exception { | ||
protected: | ||
|
||
/// Constructor. | ||
/// @param title Title of the exception. | ||
/// @param location Source location of the exception. | ||
/// | ||
Exception(const std::string& title, const std::source_location& location); | ||
|
||
/// Constructor. | ||
/// @param title Title of the exception. | ||
/// @param message Message of the exception. | ||
/// @param location Source location of the exception. | ||
/// | ||
Exception(const std::string& title, const std::string& message, const std::source_location& location); | ||
|
||
public: | ||
Exception(const std::string& title); | ||
/// print the exception to the console. | ||
/// @param level Log level of the exception. | ||
/// | ||
void print(LogLevel level = LogLevel::error) const; | ||
|
||
// Inherited form std::exception Get Exception message. | ||
/// @return Exception message. | ||
/// | ||
const char* what() const noexcept override; | ||
|
||
protected: | ||
void _appendMsg(const std::string& msg); | ||
/// Get the title of the exception. | ||
/// @return Title of the exception. | ||
/// | ||
std::string_view title() const; | ||
|
||
/// Get the message of the exception. | ||
/// @return Message of the exception. | ||
/// | ||
std::string_view message() const; | ||
|
||
private: | ||
std::string _msg; | ||
/// Get the source location of the exception. | ||
/// @return Source location of the exception. | ||
/// | ||
const std::source_location& location() const; | ||
|
||
protected: | ||
std::string _title; | ||
std::string _message; | ||
std::source_location _location; | ||
}; | ||
|
||
} // namespace arch |
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 |
---|---|---|
@@ -1,18 +1,21 @@ | ||
#pragma once | ||
|
||
#include <exception> | ||
#include <string> | ||
|
||
#include "Exception.h" | ||
|
||
namespace arch { | ||
|
||
class ConfigException: public std::exception { | ||
/// Exception thrown when an error occurs during loading of configuration. | ||
/// @see Exception | ||
/// | ||
class ConfigException final: public Exception { | ||
public: | ||
explicit ConfigException(const std::string& message = ""); | ||
|
||
[[nodiscard]] const char* what() const noexcept override; | ||
|
||
private: | ||
std::string _message; | ||
/// Constructor. | ||
/// @param message Message of the exception. | ||
/// @param location Source location of the exception. | ||
/// | ||
ConfigException(const std::string& message, const std::source_location& location = std::source_location::current()); | ||
}; | ||
|
||
} // namespace arch |
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 |
---|---|---|
@@ -1,18 +1,21 @@ | ||
#pragma once | ||
|
||
#include <exception> | ||
#include <string> | ||
|
||
#include "Exception.h" | ||
|
||
namespace arch { | ||
|
||
class InitException: public std::exception { | ||
/// Exception thrown when an error occurs during initialization. | ||
/// @see Exception | ||
/// | ||
class InitException final: public Exception { | ||
public: | ||
explicit InitException(const std::string& message = ""); | ||
|
||
[[nodiscard]] const char* what() const noexcept override; | ||
|
||
private: | ||
std::string _message; | ||
/// Constructor. | ||
/// @param message Message of the exception. | ||
/// @param location Source location of the exception. | ||
/// | ||
InitException(const std::string& message, const std::source_location& location = std::source_location::current()); | ||
}; | ||
|
||
} // namespace arch |
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
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