exception.h revision d02f89424319afe28fe2cc6696c28108448de3ac
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos/** Defines the different types of exceptions that 2geom can throw.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Copyright 2007 Johan Engelen <goejendaagh@zonnet.nl>
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * This library is free software; you can redistribute it and/or
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * modify it either under the terms of the GNU Lesser General Public
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * License version 2.1 as published by the Free Software Foundation
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * (the "LGPL") or, at your option, under the terms of the Mozilla
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Public License Version 1.1 (the "MPL"). If you do not alter this
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * notice, a recipient may use your version of this file under either
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * the MPL or the LGPL.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * You should have received a copy of the LGPL along with this library
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * in the file COPYING-LGPL-2.1; if not, write to the Free Software
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * You should have received a copy of the MPL along with this library
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * in the file COPYING-MPL-1.1
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * The contents of this file are subject to the Mozilla Public License
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * Version 1.1 (the "License"); you may not use this file except in
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * compliance with the License. You may obtain a copy of the License at
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * OF ANY KIND, either express or implied. See the LGPL or the MPL for
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos * the specific language governing rights and limitations.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos// Base exception class, all 2geom exceptions should be derived from this one.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Exception(const char * message, const char *file, const int line) {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos os << "lib2geom exception: " << message << " (" << file << ":" << line << ")";
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos virtual ~Exception() throw() {} // necessary to destroy the string object!!!
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#define THROW_EXCEPTION(message) throw(Geom::Exception(message, __FILE__, __LINE__))
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos//-----------------------------------------------------------------------
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos// Two main exception classes: LogicalError and RangeError.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos// Logical errors are 2geom faults/bugs, RangeErrors are 'user' faults.
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos// This way, the 'user' can distinguish between groups of exceptions
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov// ('user' is the coder that uses lib2geom)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos LogicalError(const char * message, const char *file, const int line)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#define THROW_LOGICALERROR(message) throw(LogicalError(message, __FILE__, __LINE__))
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos RangeError(const char * message, const char *file, const int line)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#define THROW_RANGEERROR(message) throw(RangeError(message, __FILE__, __LINE__))
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos//-----------------------------------------------------------------------
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos// Special case exceptions. Best used with the defines :)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos : LogicalError("Method not implemented", file, line) {}
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#define THROW_NOTIMPLEMENTED(i) throw(NotImplemented(__FILE__, __LINE__))
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos InvariantsViolation(const char *file, const int line)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos : LogicalError("Invariants violation", file, line) {}
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#define THROW_INVARIANTSVIOLATION(i) throw(InvariantsViolation(__FILE__, __LINE__))
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#define ASSERT_INVARIANTS(e) ((e) ? (void)0 : THROW_INVARIANTSVIOLATION())
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos : RangeError("Function does not have a unique inverse", file, line) {}
a81e80c817808f4bb41d5219b04dbf73c943821eNikolai Kondrashov#define THROW_NOTINVERTIBLE(i) throw(NotInvertible(__FILE__, __LINE__))
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos InfiniteSolutions(const char *file, const int line)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos : RangeError("There are infinite solutions", file, line) {}
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#define THROW_INFINITESOLUTIONS(i) throw(InfiniteSolutions(__FILE__, __LINE__))
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos ContinuityError(const char *file, const int line)
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos : RangeError("Non-contiguous path", file, line) {}
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos#define THROW_CONTINUITYERROR(i) throw(ContinuityError(__FILE__, __LINE__))
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kosstruct SVGPathParseError : public std::exception {
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos char const *what() const throw() { return "parse error"; }
a5f79cce8abc74beec0c27c477c046bb6cbe7101Simo Sorce} // namespace Geom
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos Local Variables:
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos c-file-style:"stroustrup"
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos indent-tabs-mode:nil
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos fill-column:99
7de6e3534fd61c7619ed34a6b1afe7230b5e6504Ondrej Kos// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :