-
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 #7 from Adamska1008/6-establish-a-complete-excepti…
…on-handling-framework 6 establish a complete exception handling framework
- Loading branch information
Showing
8 changed files
with
268 additions
and
130 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,3 +1,6 @@ | ||
[submodule "deps/Catch2"] | ||
path = deps/Catch2 | ||
url = https://github.com/catchorg/Catch2.git | ||
[submodule "deps/fmt"] | ||
path = deps/fmt | ||
url = https://github.com/fmtlib/fmt |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "error.hpp" | ||
|
||
namespace myxml | ||
{ | ||
ParseError::ParseError(std::string message) | ||
: message(message) | ||
{ | ||
} | ||
|
||
const char *ParseError::what() const noexcept | ||
{ | ||
this->fullMessage = this->prefix() + this->message; | ||
return this->fullMessage.c_str(); | ||
} | ||
|
||
const char *SyntaxError::prefix() const | ||
{ | ||
return "Syntax Error: "; | ||
} | ||
|
||
SyntaxError::SyntaxError(std::string message) | ||
: ParseError(message) | ||
{ | ||
} | ||
|
||
const char *SemanticError::prefix() const | ||
{ | ||
return "Sematic Error: "; | ||
} | ||
|
||
SemanticError::SemanticError(std::string message) | ||
: ParseError(message) | ||
{ | ||
} | ||
|
||
const char *UnexpectedEndOfInput::prefix() const | ||
{ | ||
return "Unexpected End of Input: "; | ||
} | ||
|
||
UnexpectedEndOfInput::UnexpectedEndOfInput() | ||
: ParseError("End of input") | ||
{ | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#pragma once | ||
#include <stdexcept> | ||
|
||
namespace myxml | ||
{ | ||
class ParseError : public std::exception | ||
{ | ||
private: | ||
virtual const char *prefix() const = 0; | ||
|
||
protected: | ||
std::string message; | ||
// store message after being concated with prefix | ||
mutable std::string fullMessage; | ||
|
||
public: | ||
ParseError(std::string message); | ||
|
||
virtual const char *what() const noexcept override; | ||
}; | ||
|
||
/** | ||
* The input data do not conform to the expected grammar rule. Including: | ||
* 1. Missing or mismatch symbols. For example, missing a '>' in the end of a tag. | ||
* 2. Unexpected token. Encounter a token that is not expected in the context. For example: extra semicolon. | ||
* ... | ||
*/ | ||
class SyntaxError : public ParseError | ||
{ | ||
private: | ||
virtual const char *prefix() const; | ||
|
||
public: | ||
SyntaxError(std::string); | ||
}; | ||
|
||
/** | ||
* | ||
*/ | ||
class SemanticError : public ParseError | ||
{ | ||
private: | ||
virtual const char *prefix() const; | ||
|
||
public: | ||
SemanticError(std::string); | ||
}; | ||
|
||
/** | ||
* e.g. EOF | ||
*/ | ||
class UnexpectedEndOfInput : public ParseError | ||
{ | ||
private: | ||
virtual const char *prefix() const; | ||
|
||
public: | ||
UnexpectedEndOfInput(); | ||
}; | ||
} |
Oops, something went wrong.