mirror of
https://github.com/PashaBibko/LX.git
synced 2026-04-04 09:59:03 +00:00
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:
47
Common/src/Error.cpp
Normal file
47
Common/src/Error.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <LX-Common.h>
|
||||
|
||||
namespace LX
|
||||
{
|
||||
RuntimeError::RuntimeError()
|
||||
{
|
||||
// Debuggers can only be attached in Debug configuration so this code is useless in Release/Distribution builds //
|
||||
#ifdef _DEBUG
|
||||
|
||||
// Checks a debugger is present before throwing a breakpoint //
|
||||
if (IsDebuggerPresent()) { __debugbreak(); }
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
InvalidFilePath::InvalidFilePath(const std::string& _name, const std::filesystem::path& path)
|
||||
: name(nullptr), fileLocation(nullptr)
|
||||
{
|
||||
// Stores the actual strings in static memory //
|
||||
|
||||
static std::string s_ErrorPath;
|
||||
static std::string s_ErrorName;
|
||||
|
||||
s_ErrorPath = path.string();
|
||||
s_ErrorName = _name;
|
||||
|
||||
// Assigns a pointer to the c-string of the strings //
|
||||
// Done like this because of how DLLs work //
|
||||
|
||||
fileLocation = s_ErrorPath.c_str();
|
||||
name = s_ErrorName.c_str();
|
||||
}
|
||||
|
||||
void InvalidFilePath::PrintToConsole() const
|
||||
{
|
||||
// Tells the user the input file could not be found and how to fix the issue //
|
||||
LX::PrintStringAsColor("Error: ", LX::Color::LIGHT_RED);
|
||||
std::cout << "Invalid " << name << ": ";
|
||||
LX::PrintStringAsColor(fileLocation, LX::Color::WHITE);
|
||||
std::cout << "\n\nMake sure the file exists and the process has the correct path to the file\n";
|
||||
}
|
||||
|
||||
const char* InvalidFilePath::ErrorType() const
|
||||
{
|
||||
return "Invalid File Path";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user