Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
exception.h
Go to the documentation of this file.
1
14/* Copyright 2007 Johan Engelen <goejendaagh@zonnet.nl>
15 *
16 * This library is free software; you can redistribute it and/or
17 * modify it either under the terms of the GNU Lesser General Public
18 * License version 2.1 as published by the Free Software Foundation
19 * (the "LGPL") or, at your option, under the terms of the Mozilla
20 * Public License Version 1.1 (the "MPL"). If you do not alter this
21 * notice, a recipient may use your version of this file under either
22 * the MPL or the LGPL.
23 *
24 * You should have received a copy of the LGPL along with this library
25 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * You should have received a copy of the MPL along with this library
28 * in the file COPYING-MPL-1.1
29 *
30 * The contents of this file are subject to the Mozilla Public License
31 * Version 1.1 (the "License"); you may not use this file except in
32 * compliance with the License. You may obtain a copy of the License at
33 * http://www.mozilla.org/MPL/
34 *
35 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
36 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
37 * the specific language governing rights and limitations.
38 *
39 */
40
41#ifndef LIB2GEOM_SEEN_EXCEPTION_H
42#define LIB2GEOM_SEEN_EXCEPTION_H
43
44#include <exception>
45#include <sstream>
46#include <string>
47
48namespace Geom {
49
53class Exception : public std::exception {
54public:
55 Exception(const char * message, const char *file, const int line) {
56 std::ostringstream os;
57 os << "lib2geom exception: " << message << " (" << file << ":" << line << ")";
58 msgstr = os.str();
59 }
60
61 ~Exception() noexcept override {} // necessary to destroy the string object!!!
62
63 const char* what() const noexcept override {
64 return msgstr.c_str();
65 }
66protected:
67 std::string msgstr;
68};
69#define THROW_EXCEPTION(message) throw(Geom::Exception(message, __FILE__, __LINE__))
70
71//-----------------------------------------------------------------------
72
73class LogicalError : public Exception {
74public:
75 LogicalError(const char * message, const char *file, const int line)
76 : Exception(message, file, line) {}
77};
78#define THROW_LOGICALERROR(message) throw(LogicalError(message, __FILE__, __LINE__))
79
80class RangeError : public Exception {
81public:
82 RangeError(const char * message, const char *file, const int line)
83 : Exception(message, file, line) {}
84};
85#define THROW_RANGEERROR(message) throw(RangeError(message, __FILE__, __LINE__))
86
87//-----------------------------------------------------------------------
88// Special case exceptions. Best used with the defines :)
89
91public:
92 NotImplemented(const char *file, const int line)
93 : LogicalError("Method not implemented", file, line) {}
94};
95#define THROW_NOTIMPLEMENTED(i) throw(NotImplemented(__FILE__, __LINE__))
96
98public:
99 InvariantsViolation(const char *file, const int line)
100 : LogicalError("Invariants violation", file, line) {}
101};
102#define THROW_INVARIANTSVIOLATION(i) throw(InvariantsViolation(__FILE__, __LINE__))
103#define ASSERT_INVARIANTS(e) ((e) ? (void)0 : THROW_INVARIANTSVIOLATION())
104
105class NotInvertible : public RangeError {
106public:
107 NotInvertible(const char *file, const int line)
108 : RangeError("Function does not have a unique inverse", file, line) {}
109};
110#define THROW_NOTINVERTIBLE(i) throw(NotInvertible(__FILE__, __LINE__))
111
113public:
114 InfiniteSolutions(const char *file, const int line)
115 : RangeError("There are infinite solutions", file, line) {}
116};
117#define THROW_INFINITESOLUTIONS(i) throw(InfiniteSolutions(__FILE__, __LINE__))
118
120private:
121 char const *const _message;
122public:
123 InfinitelyManySolutions(const char *file, const int line, char const *message)
124 : RangeError("There are infinitely many solutions", file, line)
125 , _message{message}
126 {}
127 char const *what() const noexcept override { return _message; }
128};
129#define THROW_INFINITELY_MANY_SOLUTIONS(msg) throw(InfinitelyManySolutions(__FILE__, __LINE__, msg))
130
132public:
133 ContinuityError(const char *file, const int line)
134 : RangeError("Non-contiguous path", file, line) {}
135};
136#define THROW_CONTINUITYERROR(i) throw(ContinuityError(__FILE__, __LINE__))
137
138struct SVGPathParseError : public std::exception {
139 char const *what() const noexcept override { return "parse error"; }
140};
141
142
143} // namespace Geom
144
145#endif
146
147
148/*
149 Local Variables:
150 mode:c++
151 c-file-style:"stroustrup"
152 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
153 indent-tabs-mode:nil
154 fill-column:99
155 End:
156*/
157// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
ContinuityError(const char *file, const int line)
Definition exception.h:133
Base exception class, all 2geom exceptions should be derived from this one.
Definition exception.h:53
~Exception() noexcept override
Definition exception.h:61
Exception(const char *message, const char *file, const int line)
Definition exception.h:55
const char * what() const noexcept override
Definition exception.h:63
std::string msgstr
Definition exception.h:67
InfiniteSolutions(const char *file, const int line)
Definition exception.h:114
char const *const _message
Definition exception.h:121
InfinitelyManySolutions(const char *file, const int line, char const *message)
Definition exception.h:123
char const * what() const noexcept override
Definition exception.h:127
InvariantsViolation(const char *file, const int line)
Definition exception.h:99
LogicalError(const char *message, const char *file, const int line)
Definition exception.h:75
NotImplemented(const char *file, const int line)
Definition exception.h:92
NotInvertible(const char *file, const int line)
Definition exception.h:107
RangeError(const char *message, const char *file, const int line)
Definition exception.h:82
Various utility functions.
Definition affine.h:22
char const * what() const noexcept override
Definition exception.h:139