1
#ifndef LIB2GEOM_EXCEPTION_HEADER
2
#define LIB2GEOM_EXCEPTION_HEADER
4
/** Defines the different types of exceptions that 2geom can throw.
6
* Copyright 2007 Johan Engelen <goejendaagh@zonnet.nl>
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.
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
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/
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.
39
// Base exception class, all 2geom exceptions should be derrived from this one.
40
class Exception : public std::exception {
42
Exception(const char * message, const char *file, const int line) {
43
std::ostringstream os;
44
os << "lib2geom exception: " << message << " (" << file << ":" << line << ")";
48
virtual ~Exception() throw() {} // necessary to destroy the string object!!!
50
virtual const char* what() const throw () {
51
return msgstr.c_str();
56
#define throwException(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 {
65
LogicalError(const char * message, const char *file, const int line)
66
: Exception(message, file, line) {}
68
#define throwLogicalError(message) throw(LogicalError(message, __FILE__, __LINE__))
70
class RangeError : public Exception {
72
RangeError(const char * message, const char *file, const int line)
73
: Exception(message, file, line) {}
75
#define throwRangeError(message) throw(RangeError(message, __FILE__, __LINE__))
77
//-----------------------------------------------------------------------
78
// Special case exceptions. Best used with the defines :)
80
class NotImplemented : public LogicalError {
82
NotImplemented(const char *file, const int line)
83
: LogicalError("Method not implemented", file, line) {}
85
#define throwNotImplemented(i) throw(NotImplemented(__FILE__, __LINE__))
87
class InvariantsViolation : public LogicalError {
89
InvariantsViolation(const char *file, const int line)
90
: LogicalError("Invariants violation", file, line) {}
92
#define throwInvariantsViolation(i) throw(InvariantsViolation(__FILE__, __LINE__))
93
#define assert_invariants(e) ((e) ? (void)0 : throwInvariantsViolation())
95
class NotInvertible : public RangeError {
97
NotInvertible(const char *file, const int line)
98
: RangeError("Function does not have a unique inverse", file, line) {}
100
#define throwNotInvertible(i) throw(NotInvertible(__FILE__, __LINE__))
102
class ContinuityError : public RangeError {
104
ContinuityError(const char *file, const int line)
105
: RangeError("Non-contiguous path", file, line) {}
107
#define throwContinuityError(i) throw(ContinuityError(__FILE__, __LINE__))
109
struct SVGPathParseError : public std::exception {
110
char const *what() const throw() { return "parse error"; }