mirror of
https://github.com/PashaBibko/LX.git
synced 2026-04-04 01:49:05 +00:00
Refactored error handling
Now uses base error class which has an abstract function for overiding how it is displayed to the console.
This commit is contained in:
24
common/Error.h
Normal file
24
common/Error.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
namespace LX
|
||||
{
|
||||
// Base error class for all LX thrown errors //
|
||||
// Holds nothing apart from the v-table //
|
||||
struct RuntimeError
|
||||
{
|
||||
// Prints the error to the console //
|
||||
// Include Common/Console.h for printing util functions //
|
||||
virtual void PrintToConsole() const = 0;
|
||||
|
||||
// Returns a C-String of the type that was thrown //
|
||||
virtual const char* ErrorType() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
// Helper macro to autogenerate a basic error type in a .h file //
|
||||
// Still requires function definitions in a .cpp file //
|
||||
#define CREATE_EMPTY_LX_ERROR_TYPE(name)\
|
||||
struct name : public LX::RuntimeError{ GENERATE_LX_ERROR_REQUIRED_FUNCTION_DECLARATIONS };
|
||||
|
||||
// Helper macro to autogenerate function declarations of functions required by LX::RuntimeError //
|
||||
#define GENERATE_LX_ERROR_REQUIRED_FUNCTION_DECLARATIONS void PrintToConsole() const; const char* ErrorType() const;
|
||||
Reference in New Issue
Block a user