~ubuntu-branches/debian/experimental/inkscape/experimental

« back to all changes in this revision

Viewing changes to src/2geom/exception.h

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-09-09 23:29:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909232902-c50iujhk1w79u8e7
Tags: 0.46-2.1
* Non-maintainer upload.
* Add upstream patch fixing a crash in the open dialog
  in the zh_CN.utf8 locale. Closes: #487623.
  Thanks to Luca Bruno for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef LIB2GEOM_EXCEPTION_HEADER
 
2
#define LIB2GEOM_EXCEPTION_HEADER
 
3
 
 
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
 */
 
32
 
 
33
#include <exception>
 
34
#include <sstream>
 
35
#include <string>
 
36
 
 
37
namespace Geom {
 
38
 
 
39
// Base exception class, all 2geom exceptions should be derrived 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
    }
 
47
 
 
48
    virtual ~Exception() throw() {} // necessary to destroy the string object!!!
 
49
 
 
50
    virtual const char* what() const throw () {
 
51
        return msgstr.c_str();
 
52
    }
 
53
protected:
 
54
    std::string msgstr;
 
55
};
 
56
#define throwException(message) throw(Geom::Exception(message, __FILE__, __LINE__))
 
57
 
 
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 throwLogicalError(message) throw(LogicalError(message, __FILE__, __LINE__))
 
69
 
 
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 throwRangeError(message) throw(RangeError(message, __FILE__, __LINE__))
 
76
 
 
77
//-----------------------------------------------------------------------
 
78
// Special case exceptions. Best used with the defines :)
 
79
 
 
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 throwNotImplemented(i) throw(NotImplemented(__FILE__, __LINE__))
 
86
 
 
87
class InvariantsViolation : public LogicalError {
 
88
public:
 
89
    InvariantsViolation(const char *file, const int line)
 
90
        : LogicalError("Invariants violation", file, line) {}
 
91
};
 
92
#define throwInvariantsViolation(i) throw(InvariantsViolation(__FILE__, __LINE__))
 
93
#define assert_invariants(e)       ((e) ? (void)0 : throwInvariantsViolation())
 
94
 
 
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 throwNotInvertible(i) throw(NotInvertible(__FILE__, __LINE__))
 
101
 
 
102
class ContinuityError : public RangeError {
 
103
public:
 
104
    ContinuityError(const char *file, const int line)
 
105
        : RangeError("Non-contiguous path", file, line) {}
 
106
};
 
107
#define throwContinuityError(i) throw(ContinuityError(__FILE__, __LINE__))
 
108
 
 
109
struct SVGPathParseError : public std::exception {
 
110
    char const *what() const throw() { return "parse error"; }
 
111
};
 
112
 
 
113
 
 
114
} // namespace Geom
 
115
 
 
116
#endif