FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
exception.hpp
Go to the documentation of this file.
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// The following line is necessary - otherwise doxygen won't document the #define's in this file.
11// includes, FEAT
13#include <kernel/util/string.hpp>
14
15// includes, system
16#include <iostream>
17
18namespace FEAT
19{
25 class Exception :
26 public std::exception
27 {
28 private:
31
32 protected:
39 explicit Exception(const String & message_in) :
40 _message(message_in)
41 {
42 }
43
53 const char* const function,
54 const char* const file,
55 const long line,
56 const String & message_in) :
57 _message(stringify(file) + ":" + stringify(line) + ": in " + stringify(function) + ": " + message_in)
58 {
59 }
60
63 {
64 }
65
66 public:
68 virtual ~Exception() noexcept
69 {
70 }
71
73 const String message() const
74 {
75 return _message;
76 }
77
79 virtual const char * what() const noexcept override
80 {
81 return _message.empty() ? std::exception::what() : _message.c_str();
82 }
83 }; // class Exception
84
85
95 public Exception
96 {
97 public:
104 explicit InternalError(const String & message_in) :
105 Exception("Internal error: " + message_in)
106 {
107 }
108
118 const char* const function,
119 const char* const file,
120 const long line,
121 const String & message_in) :
122 Exception(function, file, line, "Internal error: " + message_in)
123 {
124 }
125 }; // class InternalError
126
131 public Exception
132 {
133 public:
140 explicit ParseError(const String& message_in) :
141 Exception("ParseError: " + message_in)
142 {
143 }
144
157 explicit ParseError(const String& name, const String& got, const String& expect) :
158 Exception("ParseError: " + name + ": expected " + expect + " but got '" + got + "'")
159 {
160 }
161
162 virtual ~ParseError() noexcept
163 {
164 }
165 }; // class ParseError
166
171 class FileError :
172 public Exception
173 {
174 public:
180 explicit FileError(const String& message_in) :
181 Exception(message_in)
182 {
183 }
184 virtual ~FileError() noexcept
185 {
186 }
187 }; // class FileError
188
197 public FileError
198 {
199 public:
205 explicit FileNotFound(const String& filename) :
206 FileError("File not found: '" + filename + "'")
207 {
208 }
209 virtual ~FileNotFound() noexcept
210 {
211 }
212 }; // class FileNotFound
213
222 public FileError
223 {
224 public:
230 explicit FileNotCreated(const String& filename) :
231 FileError("Could not create file: '" + filename + "'")
232 {
233 }
234 virtual ~FileNotCreated() noexcept
235 {
236 }
237 }; // class FileNotCreated
238
249 public Exception
250 {
251 protected:
254
255 public:
265 explicit SyntaxError(
266 String message_in,
267 String filename = ""):
268 Exception(message_in + (filename.empty() ? "": " in file " + filename)),
269 _filename(filename)
270 {
271 }
272
274 virtual ~SyntaxError() noexcept
275 {
276 }
277
280 {
281 return _filename;
282 }
283 }; // class SyntaxError
284} // namespace FEAT
FEAT Kernel base header.
Base exception class.
Definition: exception.hpp:27
Exception(const Exception &)
copy CTOR
Definition: exception.hpp:62
const String _message
descriptive error message
Definition: exception.hpp:30
virtual ~Exception() noexcept
DTOR.
Definition: exception.hpp:68
Exception(const char *const function, const char *const file, const long line, const String &message_in)
CTOR.
Definition: exception.hpp:52
virtual const char * what() const noexcept override
return descriptive exception name
Definition: exception.hpp:79
const String message() const
returns error message
Definition: exception.hpp:73
Exception(const String &message_in)
CTOR.
Definition: exception.hpp:39
Base class for file related errors.
Definition: exception.hpp:173
FileError(const String &message_in)
Constructor.
Definition: exception.hpp:180
File-Not-Created exception.
Definition: exception.hpp:223
FileNotCreated(const String &filename)
Constructor.
Definition: exception.hpp:230
File-Not-Found exception.
Definition: exception.hpp:198
FileNotFound(const String &filename)
Constructor.
Definition: exception.hpp:205
exception that is thrown if something that is never supposed to happen happens
Definition: exception.hpp:96
InternalError(const char *const function, const char *const file, const long line, const String &message_in)
Constructor.
Definition: exception.hpp:117
InternalError(const String &message_in)
Constructor.
Definition: exception.hpp:104
Class for parser related errors.
Definition: exception.hpp:132
ParseError(const String &message_in)
Constructor.
Definition: exception.hpp:140
ParseError(const String &name, const String &got, const String &expect)
Constructor.
Definition: exception.hpp:157
String class implementation.
Definition: string.hpp:46
Syntax Error exception class.
Definition: exception.hpp:250
String _filename
name of the file containing the syntax error
Definition: exception.hpp:253
virtual ~SyntaxError() noexcept
virtual destructor
Definition: exception.hpp:274
SyntaxError(String message_in, String filename="")
Constructor.
Definition: exception.hpp:265
String get_filename() const
returns the filename
Definition: exception.hpp:279
FEAT namespace.
Definition: adjactor.hpp:12
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:944