Code

Correct path separators and missed variable assignment due to indention
[inkscape.git] / src / 2geom / exception.h
1 #ifndef LIB2GEOM_EXCEPTION_HEADER
2 #define LIB2GEOM_EXCEPTION_HEADER
4 /** Defines the different types of exceptions that 2geom can throw.
5  *
6  * Copyright 2007 Johan Engelen <goejendaagh@zonnet.nl>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it either under the terms of the GNU Lesser General Public
10  * License version 2.1 as published by the Free Software Foundation
11  * (the "LGPL") or, at your option, under the terms of the Mozilla
12  * Public License Version 1.1 (the "MPL"). If you do not alter this
13  * notice, a recipient may use your version of this file under either
14  * the MPL or the LGPL.
15  *
16  * You should have received a copy of the LGPL along with this library
17  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  * You should have received a copy of the MPL along with this library
20  * in the file COPYING-MPL-1.1
21  *
22  * The contents of this file are subject to the Mozilla Public License
23  * Version 1.1 (the "License"); you may not use this file except in
24  * compliance with the License. You may obtain a copy of the License at
25  * http://www.mozilla.org/MPL/
26  *
27  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
28  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
29  * the specific language governing rights and limitations.
30  *
31  */
33 #include <exception>
34 #include <sstream>
35 #include <string>
37 namespace Geom {
39 // Base exception class, all 2geom exceptions should be derived from this one.
40 class Exception : public std::exception {
41 public:
42     Exception(const char * message, const char *file, const int line) {
43         std::ostringstream os;
44         os << "lib2geom exception: " << message << " (" << file << ":" << line << ")";
45         msgstr = os.str();
46     }
48     virtual ~Exception() throw() {} // necessary to destroy the string object!!!
50     virtual const char* what() const throw () {
51         return msgstr.c_str();
52     }
53 protected:
54     std::string msgstr;
55 };
56 #define THROW_EXCEPTION(message) throw(Geom::Exception(message, __FILE__, __LINE__))
58 //-----------------------------------------------------------------------
59 // Two main exception classes: LogicalError and RangeError.
60 // Logical errors are 2geom faults/bugs, RangeErrors are 'user' faults.
61 // This way, the 'user' can distinguish between groups of exceptions
62 // ('user' is the coder that uses lib2geom)
63 class LogicalError : public Exception {
64 public:
65     LogicalError(const char * message, const char *file, const int line)
66         : Exception(message, file, line) {}
67 };
68 #define THROW_LOGICALERROR(message) throw(LogicalError(message, __FILE__, __LINE__))
70 class RangeError : public Exception {
71 public:
72     RangeError(const char * message, const char *file, const int line)
73         : Exception(message, file, line) {}
74 };
75 #define THROW_RANGEERROR(message) throw(RangeError(message, __FILE__, __LINE__))
77 //-----------------------------------------------------------------------
78 // Special case exceptions. Best used with the defines :)
80 class NotImplemented : public LogicalError {
81 public:
82     NotImplemented(const char *file, const int line)
83         : LogicalError("Method not implemented", file, line) {}
84 };
85 #define THROW_NOTIMPLEMENTED(i) throw(NotImplemented(__FILE__, __LINE__))
87 class InvariantsViolation : public LogicalError {
88 public:
89     InvariantsViolation(const char *file, const int line)
90         : LogicalError("Invariants violation", file, line) {}
91 };
92 #define THROW_INVARIANTSVIOLATION(i) throw(InvariantsViolation(__FILE__, __LINE__))
93 #define ASSERT_INVARIANTS(e)       ((e) ? (void)0 : THROW_INVARIANTSVIOLATION())
95 class NotInvertible : public RangeError {
96 public:
97     NotInvertible(const char *file, const int line)
98         : RangeError("Function does not have a unique inverse", file, line) {}
99 };
100 #define THROW_NOTINVERTIBLE(i) throw(NotInvertible(__FILE__, __LINE__))
102 class InfiniteSolutions : public RangeError {
103 public:
104         InfiniteSolutions(const char *file, const int line)
105         : RangeError("There are infinite solutions", file, line) {}
106 };
107 #define THROW_INFINITESOLUTIONS(i) throw(InfiniteSolutions(__FILE__, __LINE__))
109 class ContinuityError : public RangeError {
110 public:
111     ContinuityError(const char *file, const int line)
112         : RangeError("Non-contiguous path", file, line) {}
113 };
114 #define THROW_CONTINUITYERROR(i) throw(ContinuityError(__FILE__, __LINE__))
116 struct SVGPathParseError : public std::exception {
117     char const *what() const throw() { return "parse error"; }
118 };
121 } // namespace Geom
123 #endif
126 /*
127   Local Variables:
128   mode:c++
129   c-file-style:"stroustrup"
130   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
131   indent-tabs-mode:nil
132   fill-column:99
133   End:
134 */
135 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :