From: johanengelen Date: Sat, 17 Nov 2007 23:52:33 +0000 (+0000) Subject: Fix exception catching, to allow polymorphism. Note to all: always catch by reference... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ab5f33e91458710ed8dd2b2a1b3a53e4227d4856;p=inkscape.git Fix exception catching, to allow polymorphism. Note to all: always catch by reference! 17.7 of C++FAQlite --- diff --git a/src/2geom/exception.h b/src/2geom/exception.h index bd950726f..1a031cab9 100644 --- a/src/2geom/exception.h +++ b/src/2geom/exception.h @@ -31,6 +31,7 @@ */ #include +#include #include namespace Geom { @@ -39,19 +40,15 @@ namespace Geom { 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 += ")"; + std::ostringstream os; + os << "lib2geom exception: " << message << " (" << file << ":" << line << ")"; + msgstr = os.str(); } virtual ~Exception() throw() {} // necessary to destroy the string object!!! - virtual const char * what() const throw (){ + virtual const char* what() const throw (){ return msgstr.c_str(); } protected: diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 4ccfa5952..8b0a2f62a 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -144,7 +144,7 @@ Effect::doEffect_nartbpath (NArtBpath * path_in) return new_bpath; } - catch (std::exception e) { + catch (std::exception & e) { 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 the Path Effect.") ); diff --git a/src/ui/dialog/filedialogimpl-gtkmm.cpp b/src/ui/dialog/filedialogimpl-gtkmm.cpp index b47e26d12..5dd8e66f2 100644 --- a/src/ui/dialog/filedialogimpl-gtkmm.cpp +++ b/src/ui/dialog/filedialogimpl-gtkmm.cpp @@ -209,12 +209,12 @@ void SVGPreview::showImage(Glib::ustring &theFileName) try { img = Gdk::Pixbuf::create_from_file(fileName); } - catch (Glib::FileError e) + catch (Glib::FileError & e) { g_message("caught Glib::FileError in SVGPreview::showImage"); return; } - catch (Gdk::PixbufError e) + catch (Gdk::PixbufError & e) { g_message("Gdk::PixbufError in SVGPreview::showImage"); return;