OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
parse_error.h
Go to the documentation of this file.
1#pragma once
2
3#include <exception>
4#include <string>
5#include <filesystem>
6#include "parse_info.h"
7
9{
10
11#ifndef throw_parse_error
12# define throw_parse_error(dataFile, dataLine, dataToken, dataLineNumber) throw parse_error(dataFile, dataLine, dataToken, dataLineNumber, __LINE__, __FILE__)
13#endif
14
15 class parse_error : public std::exception
16 {
17 public:
18
19 parse_error(std::filesystem::path dataFile, const std::string& szDataLine, const std::string& szDataToken, int dataLineNumber, int sourceLine, const char* szSourceFile)
20 : m_parseInfo(dataFile, szDataLine, szDataToken, dataLineNumber), sourceLine(sourceLine), sourceFile(szSourceFile)
21 {
22 }
23
24 parse_error(const char* szDataFile, const char* szDataLine, const char* szDataToken, int sourceLine, const char* szSourceFile)
25 : parse_error(szDataFile, szDataLine, szDataToken, -1, sourceLine, szSourceFile)
26 {
27 }
28
29 parse_error(const char* szDataFile, const char* szDataLine, int sourceLine, const char* szSourceFile)
30 : parse_error(szDataFile, szDataLine, "", -1, sourceLine, szSourceFile)
31 {
32 }
33
34 parse_error(const char* szDataFile, int sourceLine, const char* szSourceFile)
35 : parse_error(szDataFile, "", "", -1, sourceLine, szSourceFile)
36 {
37 }
38
39 std::string toString(const std::string& message = "") const;
40
41 const parse_info& getParseInfo() const;
42
43 // "<source basename>:<line>", e.g. "FeaturesFile.cpp:623" — the throw
44 // site without the absolute build path, for client-facing messages
45 std::string sourceLocation() const;
46
47 [[nodiscard]] char const* what() const noexcept;
48
49 private:
50 // data file
51 const parse_info m_parseInfo;
52
53 // source file
54 int sourceLine;
55 std::filesystem::path sourceFile;
56
57 constexpr inline static const char WHAT_STR[] = "Parse error";
58
59 };
60}
std::string error
const parse_info & getParseInfo() const
std::string toString(const std::string &message="") const
char const * what() const noexcept
parse_error(const char *szDataFile, const char *szDataLine, int sourceLine, const char *szSourceFile)
Definition parse_error.h:29
parse_error(const char *szDataFile, const char *szDataLine, const char *szDataToken, int sourceLine, const char *szSourceFile)
Definition parse_error.h:24
parse_error(const char *szDataFile, int sourceLine, const char *szSourceFile)
Definition parse_error.h:34
std::string sourceLocation() const
parse_error(std::filesystem::path dataFile, const std::string &szDataLine, const std::string &szDataToken, int dataLineNumber, int sourceLine, const char *szSourceFile)
Definition parse_error.h:19