summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2007-11-17 01:44:59 +0000
committerjohanengelen <johanengelen@users.sourceforge.net>2007-11-17 01:44:59 +0000
commit2da1c6d283b560c7405a89cfc368ea6a554a68a7 (patch)
treea146e9f0b325dfdca9de28d6730d645bc70db3d7 /src
parenthopefully fix compile (#include <errno.h> (diff)
downloadinkscape-2da1c6d283b560c7405a89cfc368ea6a554a68a7.tar.gz
inkscape-2da1c6d283b560c7405a89cfc368ea6a554a68a7.zip
2geom tryout: new exceptions
(bzr r4094)
Diffstat (limited to 'src')
-rw-r--r--src/2geom/basic-intersection.cpp2
-rw-r--r--src/2geom/path.cpp10
-rw-r--r--src/2geom/path.h5
-rw-r--r--src/2geom/piecewise.h2
-rw-r--r--src/2geom/sbasis.h3
-rw-r--r--src/2geom/shape.cpp2
-rw-r--r--src/2geom/utils.h67
-rw-r--r--src/live_effects/effect.cpp4
8 files changed, 77 insertions, 18 deletions
diff --git a/src/2geom/basic-intersection.cpp b/src/2geom/basic-intersection.cpp
index 0d84ee7f3..ee1244a73 100644
--- a/src/2geom/basic-intersection.cpp
+++ b/src/2geom/basic-intersection.cpp
@@ -60,7 +60,7 @@ find_intersections( vector<Geom::Point> const & A,
std::vector<std::pair<double, double> >
find_self_intersections(OldBezier const &Sb) {
- throw NotImplemented();
+ throwNotImplemented();
}
std::vector<std::pair<double, double> >
diff --git a/src/2geom/path.cpp b/src/2geom/path.cpp
index 98fec6e24..ba6643ae4 100644
--- a/src/2geom/path.cpp
+++ b/src/2geom/path.cpp
@@ -222,21 +222,21 @@ void Path::check_continuity(Sequence::iterator first_replaced,
}
Rect SVGEllipticalArc::boundsFast() const {
- throw NotImplemented();
+ throwNotImplemented();
}
Rect SVGEllipticalArc::boundsExact() const {
- throw NotImplemented();
+ throwNotImplemented();
}
Rect SVGEllipticalArc::boundsLocal(Interval i, unsigned deg) const {
- //throw NotImplemented();
+ throwNotImplemented();
}
std::vector<Point> SVGEllipticalArc::pointAndDerivatives(Coord t, unsigned n) const {
- throw NotImplemented();
+ throwNotImplemented();
}
std::vector<double> SVGEllipticalArc::roots(double v, Dim2 d) const {
- //throw NotImplemented();
+ throwNotImplemented();
}
D2<SBasis> SVGEllipticalArc::toSBasis() const {
diff --git a/src/2geom/path.h b/src/2geom/path.h
index 46d7f230a..053bc06c9 100644
--- a/src/2geom/path.h
+++ b/src/2geom/path.h
@@ -39,6 +39,7 @@
#include "matrix.h"
#include "bezier.h"
#include "crossing.h"
+#include "utils.h"
namespace Geom {
@@ -325,7 +326,7 @@ public:
return ret;
}
- Curve *derivative() const { throw NotImplemented(); }
+ Curve *derivative() const { throwNotImplemented(); }
std::vector<Point> pointAndDerivatives(Coord t, unsigned n) const;
@@ -767,7 +768,7 @@ class PathPortion : public Curve {
Rect boundsFast() const { return actualPath().boundsFast; }
Rect boundsExact() const { return actualPath().boundsFast; }
- Rect boundsLocal(Interval i) const { throw NotImplemented(); }
+ Rect boundsLocal(Interval i) const { throwNotImplemented(); }
std::vector<double> roots(double v, Dim2 d) const = 0;
diff --git a/src/2geom/piecewise.h b/src/2geom/piecewise.h
index b4f000dc4..c70ecd42c 100644
--- a/src/2geom/piecewise.h
+++ b/src/2geom/piecewise.h
@@ -90,7 +90,7 @@ class Piecewise {
}
//Convenience/implementation hiding function to add cuts.
inline void push_cut(double c) {
- assert(cuts.empty() || c > cuts.back());
+ assert_invariants(cuts.empty() || c > cuts.back());
cuts.push_back(c);
}
//Convenience/implementation hiding function to add segments.
diff --git a/src/2geom/sbasis.h b/src/2geom/sbasis.h
index 9fc16f1c6..df41dca58 100644
--- a/src/2geom/sbasis.h
+++ b/src/2geom/sbasis.h
@@ -106,7 +106,8 @@ public:
std::vector<double> valueAndDerivatives(double /*t*/, unsigned /*n*/) const {
//TODO
- throw NotImplemented();
+ throwNotImplemented();
+ //throw(NotImplemented(__FILE__, __LINE__));
}
SBasis toSBasis() const { return SBasis(*this); }
diff --git a/src/2geom/shape.cpp b/src/2geom/shape.cpp
index 3cf6d0bc0..70a7d0884 100644
--- a/src/2geom/shape.cpp
+++ b/src/2geom/shape.cpp
@@ -191,7 +191,7 @@ Shape shape_boolean_rb(bool rev, Shape const &a, Shape const &b, CrossingSet con
* NOTE: currently doesn't work, as the CrossingSet reversal functions crash
*/
Shape boolop(Shape const &a, Shape const &b, unsigned flags, CrossingSet const &crs) {
- throw NotImplemented();
+ throwNotImplemented();
flags &= 15;
if(flags <= BOOLOP_UNION) {
switch(flags) {
diff --git a/src/2geom/utils.h b/src/2geom/utils.h
index 50dfa82fe..cd2a9c26c 100644
--- a/src/2geom/utils.h
+++ b/src/2geom/utils.h
@@ -3,6 +3,7 @@
/** Various utility functions.
*
+ * Copyright 2007 Johan Engelen <goejendaagh@zonnet.nl>
* Copyright 2006 Michael G. Sloan <mgsloan@gmail.com>
*
* This library is free software; you can redistribute it and/or
@@ -35,15 +36,71 @@
namespace Geom {
-class NotImplemented : public std::logic_error {
+
+//#######################################################################
+// Base exception class, all 2geom exceptions should be derrived from this one.
+class Exception : public std::exception {
+public:
+ Exception(const char * message, const char *file, const int line) {
+ msgstr = "Exception thrown: ";
+ msgstr += message;
+ msgstr += " (";
+ msgstr += file;
+ msgstr += ":";
+ msgstr += line;
+ msgstr += ")";
+ };
+ virtual ~Exception() throw() {}; // necessary to destroy the string object!!!
+ virtual const char * what() const throw () { return msgstr.c_str(); }
+protected:
+ std::string msgstr;
+};
+
+//-----------------------------------------------------------------------
+// Two main exception classes: LogicalError and RangeError.
+// Logical errors are 2geom faults/bugs, RangeErrors are 'user' faults.
+// This way, the 'user' can distinguish between groups of exceptions
+// ('user' is the coder that uses lib2geom)
+class LogicalError : public Exception {
+public:
+ LogicalError(const char * message, const char *file, const int line)
+ : Exception(message, file, line) {};
+};
+#define throwLogicalError(message) throw(LogicalError(message, __FILE__, __LINE__))
+
+class RangeError : public Exception {
+public:
+ RangeError(const char * message, const char *file, const int line)
+ : Exception(message, file, line) {};
+};
+#define throwRangeError(message) throw(RangeError(message, __FILE__, __LINE__))
+
+//-----------------------------------------------------------------------
+// Special case exceptions. Best used with the defines :)
+
+class NotImplemented : public LogicalError {
+public:
+ NotImplemented(const char *file, const int line)
+ : LogicalError("Method not implemented", file, line) {};
+};
+#define throwNotImplemented(i) throw(NotImplemented(__FILE__, __LINE__))
+
+class InvariantsViolation : public LogicalError {
public:
- NotImplemented() : std::logic_error("method not implemented") {}
+ InvariantsViolation(const char *file, const int line)
+ : LogicalError("Invariants violation", file, line) {};
};
+#define throwInvariantsViolation(i) throw(InvariantsViolation(__FILE__, __LINE__))
+#define assert_invariants(e) ((e) ? (void)0 : throwInvariantsViolation())
-class NotInvertible : public std::range_error {
- public:
- NotInvertible() : std::range_error("function does not have a unique inverse") {}
+class NotInvertible : public RangeError {
+public:
+ NotInvertible(const char *file, const int line)
+ : RangeError("Function does not have a unique inverse", file, line) {};
};
+#define throwNotInvertible(i) throw(NotInvertible(__FILE__, __LINE__))
+
+//#######################################################################
// proper logical xor
inline bool logical_xor (bool a, bool b) { return (a || b) && !(a && b); }
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp
index f87e365bc..4ccfa5952 100644
--- a/src/live_effects/effect.cpp
+++ b/src/live_effects/effect.cpp
@@ -145,9 +145,9 @@ Effect::doEffect_nartbpath (NArtBpath * path_in)
return new_bpath;
}
catch (std::exception e) {
- g_warning("An exception occurred during execution of an LPE - %s", e.what());
+ g_warning("Exception during LPE %s execution. \n %s", getName().c_str(), e.what());
SP_ACTIVE_DESKTOP->messageStack()->flash( Inkscape::WARNING_MESSAGE,
- _("An exception occurred during execution of a Path Effect.") );
+ _("An exception occurred during execution of the Path Effect.") );
NArtBpath *path_out;