LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
Exceptions.h
Go to the documentation of this file.
1// Copyright 2002-2020 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6// NAUTITIA
7//
8// jys 18-JUL-2002
9//
10// This file holds exceptions classes for S2 project
11
12#ifndef Exceptions_H
13#define Exceptions_H
14
15#include <stdexcept>
16
18
19
20namespace Lima {
21
22
23// when binary file is syntactically wrong
24class BadFileException : public std::runtime_error {
25public:
27 BadFileException(const std::string s = "Bad file error") :
28 runtime_error(s),
30 BadFileException(uint32_t expectedAddress) :
31 runtime_error("Bad file error"),
32 _expectedAddress(expectedAddress) {}
33 virtual ~BadFileException() throw() {}
34};
35
36// when character is searched out of text buffer
37class BoundsErrorException : public std::out_of_range {
38public:
39 BoundsErrorException(const std::string s = "Bound Error") :
40 out_of_range(s) {}
41};
42
43// when attemp to use an empty entry from dictionary
44class EmptyEntryException : public std::domain_error {
45public:
46 EmptyEntryException(const std::string s = "Empty entry") :
47 domain_error(s) {}
48};
49// when EOF occurs (it can be a valid test of EOF)
50class EofException : public std::runtime_error {
51public:
52 EofException(const std::string s = "Eof") :
53 runtime_error(s) {}
54};
55// when an main Tokenizer Automaton goes in infinite loop
56class InfiniteLoopException : public std::runtime_error {
57public:
58 InfiniteLoopException(const std::string s = "Infinite loop") :
59 runtime_error(s) {}
60};
61// when an unexpected case appears
62class InternalErrorException : public std::logic_error {
63public:
64 InternalErrorException(const std::string s = "Internal error") :
65 logic_error(s) {}
66};
67// when an invalid character is used
68class InvalidCharException : public std::runtime_error {
69public:
70 InvalidCharException(const std::string s = "Invalid char") :
71 runtime_error(s) {}
72};
73// when an invalid UNICODE file is used
74class InvalidFileException : public std::runtime_error {
75public:
76 InvalidFileException(const std::string s = "Invalid file") :
77 runtime_error(s) {}
78};
79// when an invalid automaton is used
80class InvAutomatonException : public std::runtime_error {
81public:
82 InvAutomatonException(const std::string s = "Invalid automaton") :
83 runtime_error(s) {}
84};
85// when an invalid coded number is encountered in binary file
86class InvNumberException : public std::runtime_error {
87public:
88 InvNumberException(const std::string s = "Invalid number") :
89 runtime_error(s) {}
90};
91// when new() fails
92class MemoryErrorException : public std::bad_alloc {
93public:
95 bad_alloc() {}
96};
97// when open file fails
98class OpenFileException : public std::runtime_error
99{
100public:
101 OpenFileException(const std::string& s) : runtime_error(s) {}
102};
103// when read error occurs on a file
104class ReadErrorException : public std::runtime_error {
105public:
106 ReadErrorException(const std::string s = "read error") :
107 runtime_error(s) {}
108};
109// when both parts of a dictionary are incompatible
110class UnconsistentDictionaryException : public std::domain_error {
111public:
112 UnconsistentDictionaryException(const std::string s = "Unconsistent dictionary") :
113 domain_error(s) {}
114};
115// when an unknown character class name is found
116class UnknownCharClassException : public std::runtime_error {
117public:
118 UnknownCharClassException(const std::string s = "Unknown char class") :
119 runtime_error(s) {}
120};
121// when an unknown language is specified
122class UnknownLanguageException : public std::runtime_error {
123public:
124 UnknownLanguageException(const std::string s = "Unknown language") :
125 runtime_error(s) {}
126};
127// when input XML file is syntactically wrong
128class XmlSyntaxException : public std::runtime_error {
129public:
130 enum Why {
131 SYNTAX_EXC, // syntax exception
132 NO_DATA_EXC, // no enclosed datas found
133 DOUBLE_EXC, // same object already defined
134 FWD_CLASS_EXC, // forward class declaration
135 MULT_CLASS_EXC, // multi class declaration
136 EOF_EXC, // unexpected EOF
137 NO_CODE_EXC, // no <code> found
138 BAD_CODE_EXC, // <code> exceeds FFFF
139 NO_CLASS_EXC, // no <char_class> found
140 UNK_CLASS_EXC, // unknown class found
141 INT_ERROR_EXC, // internal error
142 INV_CLASS_EXC // invalid class found
143 };
144 uint32_t _lineNumber;
147 XmlSyntaxException(const std::string s = "XML syntax error") :
148 runtime_error(s) {}
150 runtime_error("XML syntax error"),
151 _why(why) {}
153 uint32_t lineNumber,
154 Why why) :
155 runtime_error("XML syntax error"),
156 _lineNumber(lineNumber),
157 _why(why) {}
159 uint32_t lineNumber,
160 Why why,
161 const Lima::LimaString& fileName) :
162 runtime_error("XML syntax error"),
163 _lineNumber(lineNumber),
164 _why(why),
165 _fileName(fileName) {}
166 virtual ~XmlSyntaxException() throw() {}
167 void set (uint32_t lineNumber) {
168 _lineNumber = lineNumber; }
169 void set (Why why) {
170 _why = why; }
171 void set (const Lima::LimaString& fileName) {
172 _fileName = fileName; }
173};
174// when input XML file is syntactically wrong
175class XmlS2SyntaxException : public std::runtime_error {
176public:
177 XmlS2SyntaxException(const std::string s = "XML syntax error") :
178 runtime_error(s) {}
179};
180
181
182} // Lima
183
184#endif
virtual ~BadFileException()
Definition Exceptions.h:33
BadFileException(uint32_t expectedAddress)
Definition Exceptions.h:30
BadFileException(const std::string s="Bad file error")
Definition Exceptions.h:27
BoundsErrorException(const std::string s="Bound Error")
Definition Exceptions.h:39
EmptyEntryException(const std::string s="Empty entry")
Definition Exceptions.h:46
EofException(const std::string s="Eof")
Definition Exceptions.h:52
InfiniteLoopException(const std::string s="Infinite loop")
Definition Exceptions.h:58
InternalErrorException(const std::string s="Internal error")
Definition Exceptions.h:64
InvAutomatonException(const std::string s="Invalid automaton")
Definition Exceptions.h:82
InvNumberException(const std::string s="Invalid number")
Definition Exceptions.h:88
InvalidCharException(const std::string s="Invalid char")
Definition Exceptions.h:70
InvalidFileException(const std::string s="Invalid file")
Definition Exceptions.h:76
OpenFileException(const std::string &s)
Definition Exceptions.h:101
ReadErrorException(const std::string s="read error")
Definition Exceptions.h:106
UnconsistentDictionaryException(const std::string s="Unconsistent dictionary")
Definition Exceptions.h:112
UnknownCharClassException(const std::string s="Unknown char class")
Definition Exceptions.h:118
UnknownLanguageException(const std::string s="Unknown language")
Definition Exceptions.h:124
XmlS2SyntaxException(const std::string s="XML syntax error")
Definition Exceptions.h:177
void set(const Lima::LimaString &fileName)
Definition Exceptions.h:171
void set(uint32_t lineNumber)
Definition Exceptions.h:167
XmlSyntaxException(const std::string s="XML syntax error")
Definition Exceptions.h:147
Lima::LimaString _fileName
Definition Exceptions.h:146
XmlSyntaxException(uint32_t lineNumber, Why why, const Lima::LimaString &fileName)
Definition Exceptions.h:158
XmlSyntaxException(uint32_t lineNumber, Why why)
Definition Exceptions.h:152
NAUTITIA.
QString LimaString
Definition LimaString.h:33