Made Lexer errors fully hidden in global scope

Also improved general ease of use with debugging use __debugbreak when an error is thrown.

NOTE: Parser errors currently crash the program
This commit is contained in:
Pasha Bibko
2025-05-07 16:31:44 +01:00
parent 0c34e7174e
commit 4e78a9f6ae
11 changed files with 161 additions and 103 deletions

View File

@@ -2,14 +2,41 @@ namespace LX
{
// Base error class for all LX thrown errors //
// Holds nothing apart from the v-table //
struct RuntimeError
struct COMMON_API RuntimeError
{
// Default constructor which throws a breakpoint on being created //
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;
// Virtual destructor because of polymorphism //
virtual ~RuntimeError() = default;
};
// --- Common errors that can be thrown --- //
// Error thrown when there is an invalid file path //
struct COMMON_API InvalidFilePath : public RuntimeError
{
// Constructor to turn the C++ types to C to expose them in DLL //
InvalidFilePath(const std::string& _name, const std::filesystem::path& path);
// Prints the error to the console //
void PrintToConsole() const;
// Returns the error as c-string //
const char* ErrorType() const;
// Name of the file that is invalid (used for console output) //
const char* name;
// The location of the file (used for console output) //
const char* fileLocation;
};
}