throw invalid arguments

This commit is contained in:
2024-10-24 18:14:09 +02:00
parent 777adffdea
commit 6fcc51f2ca

View File

@@ -53,7 +53,7 @@ std::uint32_t Assembleur::ParseLabel(const std::string& a_Label) {
auto it = m_Labels.find(a_Label); auto it = m_Labels.find(a_Label);
if (it == m_Labels.end()) { if (it == m_Labels.end()) {
throw std::runtime_error("Label " + a_Label + " not found !"); throw std::invalid_argument("Label " + a_Label + " not found !");
} }
return it->second; return it->second;
@@ -105,10 +105,10 @@ std::uint32_t Assembleur::ParseIO(Instruction a_Instruction, std::uint32_t a_R1,
static std::uint32_t ParseRegistry(const std::string& a_Str) { static std::uint32_t ParseRegistry(const std::string& a_Str) {
if (a_Str.at(0) != 'R') if (a_Str.at(0) != 'R')
throw std::runtime_error("Registry " + a_Str + " not found !"); throw std::invalid_argument("Registry " + a_Str + " not found !");
std::uint32_t registry = std::stoi(a_Str.substr(1)); std::uint32_t registry = std::stoi(a_Str.substr(1));
if (registry > 7) if (registry > 7)
throw std::runtime_error("You can only have up to 8 registries !"); throw std::invalid_argument("You can only have up to 8 registries !");
return registry; return registry;
} }
@@ -118,7 +118,7 @@ static bool IsConstant(const std::string& a_Str) {
static std::uint32_t ParseConstant(const std::string& a_Str) { static std::uint32_t ParseConstant(const std::string& a_Str) {
if (a_Str.at(0) != '#') if (a_Str.at(0) != '#')
throw std::runtime_error("Registry " + a_Str + " not found !"); throw std::invalid_argument("Registry " + a_Str + " not found !");
return std::stoi(a_Str.substr(1)); return std::stoi(a_Str.substr(1));
} }
@@ -129,7 +129,7 @@ std::uint32_t Assembleur::ParseInstruction(const std::string& a_Str, std::uint32
auto it = INSTRUCTION_KEYS.find(ins); auto it = INSTRUCTION_KEYS.find(ins);
if (it == INSTRUCTION_KEYS.end()) { if (it == INSTRUCTION_KEYS.end()) {
throw std::runtime_error("[Line " + std::to_string(a_RealLine) + "] " + "Instruction \"" + ins + "\" not found !"); throw std::invalid_argument("[Line " + std::to_string(a_RealLine) + "] " + "Instruction \"" + ins + "\" not found !");
} }
Instruction instruction = it->second; Instruction instruction = it->second;
@@ -177,8 +177,8 @@ std::uint32_t Assembleur::ParseInstruction(const std::string& a_Str, std::uint32
} }
} }
} catch (std::runtime_error& e) { } catch (std::invalid_argument& e) {
throw std::runtime_error("[Line " + std::to_string(a_RealLine) + "] " + e.what()); throw std::invalid_argument("[Line " + std::to_string(a_RealLine) + "] " + e.what());
} }
return 0; return 0;