Add base QueryException class
Summary: Also, inherit `TypedValueException` from `BasicException` instead of `StacktraceException`. This is meant as a basic API change, so that catching query exceptions becomes simpler. The error message can be obtained from `what` method, inherited from `BasicException`. In the future, we may extend the `QueryException`. It could take column/row position in query source, as well as other information. Then provide (or override `what`) a method to format the error message nicely for the user. Reviewers: florijan, buda, mislav.bradac Reviewed By: mislav.bradac Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D267
This commit is contained in:
parent
ea202dc52a
commit
b69c162c9f
@ -150,6 +150,8 @@ void query::Repl(Dbms &dbms) {
|
||||
std::cout << "SEMANTIC EXCEPTION: " << e.what() << std::endl;
|
||||
} catch (const query::QueryRuntimeException &e) {
|
||||
std::cout << "RUNTIME EXCEPTION: " << e.what() << std::endl;
|
||||
} catch (const query::TypedValueException &e) {
|
||||
std::cout << "TYPED VALUE EXCEPTION: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,10 +7,16 @@
|
||||
|
||||
namespace query {
|
||||
|
||||
class SyntaxException : public BasicException {
|
||||
public:
|
||||
/** @brief Base class of all query language related exceptions.
|
||||
*/
|
||||
class QueryException : public BasicException {
|
||||
using BasicException::BasicException;
|
||||
SyntaxException() : BasicException("") {}
|
||||
};
|
||||
|
||||
class SyntaxException : public QueryException {
|
||||
public:
|
||||
using QueryException::QueryException;
|
||||
SyntaxException() : QueryException("") {}
|
||||
};
|
||||
|
||||
// TODO: Figure out what information to put in exception.
|
||||
@ -22,10 +28,10 @@ class SyntaxException : public BasicException {
|
||||
// query and only report line numbers of semantic errors (not position in the
|
||||
// line) if multiple line strings are not allowed by grammar. We could also
|
||||
// print whole line that contains error instead of specifying line number.
|
||||
class SemanticException : public BasicException {
|
||||
class SemanticException : public QueryException {
|
||||
public:
|
||||
using BasicException::BasicException;
|
||||
SemanticException() : BasicException("") {}
|
||||
using QueryException::QueryException;
|
||||
SemanticException() : QueryException("") {}
|
||||
};
|
||||
|
||||
class UnboundVariableError : public SemanticException {
|
||||
@ -53,9 +59,9 @@ class TypeMismatchError : public SemanticException {
|
||||
* An exception for an illegal operation that can not be detected
|
||||
* before the query starts executing over data.
|
||||
*/
|
||||
class QueryRuntimeException : public BasicException {
|
||||
class QueryRuntimeException : public QueryException {
|
||||
public:
|
||||
using BasicException::BasicException;
|
||||
using QueryException::QueryException;
|
||||
};
|
||||
|
||||
class CppCodeGeneratorException : public StacktraceException {
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "storage/property_value.hpp"
|
||||
#include "storage/vertex_accessor.hpp"
|
||||
#include "traversal/path.hpp"
|
||||
#include "utils/exceptions/stacktrace_exception.hpp"
|
||||
#include "utils/exceptions/basic_exception.hpp"
|
||||
#include "utils/total_ordering.hpp"
|
||||
#include "utils/underlying_cast.hpp"
|
||||
|
||||
@ -165,9 +165,9 @@ class TypedValue : public TotalOrdering<TypedValue, TypedValue, TypedValue> {
|
||||
* trying to perform operations (such as addition) on TypedValues
|
||||
* of incompatible Types.
|
||||
*/
|
||||
class TypedValueException : public StacktraceException {
|
||||
class TypedValueException : public BasicException {
|
||||
public:
|
||||
using ::StacktraceException::StacktraceException;
|
||||
using ::BasicException::BasicException;
|
||||
};
|
||||
|
||||
// comparison operators
|
||||
|
@ -3,6 +3,7 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <stdexcept>
|
||||
|
||||
/**
|
||||
@ -19,14 +20,35 @@ class BasicException : public std::exception {
|
||||
* Hence, responsibility for deleting the char* lies
|
||||
* with the caller.
|
||||
*/
|
||||
explicit BasicException(const char* message) : msg_(message) {}
|
||||
explicit BasicException(const char *message) : msg_(message) {}
|
||||
|
||||
/**
|
||||
* Constructor (C++ STL strings).
|
||||
*
|
||||
* @param message The error message.
|
||||
*/
|
||||
explicit BasicException(const std::string& message) : msg_(message) {}
|
||||
explicit BasicException(const std::string &message) : msg_(message) {}
|
||||
|
||||
/** Constructor with format string (C++ STL strings).
|
||||
*
|
||||
* @param format The error format message.
|
||||
* @param args Arguments for format string.
|
||||
*/
|
||||
template <class... Args>
|
||||
explicit BasicException(const std::string &format, Args &&... args) noexcept
|
||||
: BasicException(fmt::format(format, std::forward<Args>(args)...)) {}
|
||||
|
||||
/** Constructor with format string (C strings).
|
||||
*
|
||||
* @param format The error format message. The string contents are copied upon
|
||||
* construction. Hence, the responsibility for deleting char* lies with the
|
||||
* caller.
|
||||
* @param args Arguments for format string.
|
||||
*/
|
||||
template <class... Args>
|
||||
explicit BasicException(const char *format, Args &&... args) noexcept
|
||||
: BasicException(fmt::format(std::string(format),
|
||||
std::forward<Args>(args)...)) {}
|
||||
|
||||
/**
|
||||
* Destructor. Virtual to allow for subclassing.
|
||||
@ -40,7 +62,7 @@ class BasicException : public std::exception {
|
||||
* is in possession of the BasicException object. Callers must
|
||||
* not attempt to free the memory.
|
||||
*/
|
||||
const char* what() const noexcept override { return msg_.c_str(); }
|
||||
const char *what() const noexcept override { return msg_.c_str(); }
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user