From f7bf16d50f6f08c66b1bae35e2dab327d560b0f3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 13 Sep 2010 14:58:52 +0200 Subject: Make odb::exception abstract Implement what() in concrete exceptions. --- odb/exception.cxx | 17 ----------------- odb/exception.hxx | 4 +--- odb/exceptions.cxx | 35 +++++++++++++++++++++++++++++++++++ odb/exceptions.hxx | 12 ++++++++++++ odb/makefile | 1 - 5 files changed, 48 insertions(+), 21 deletions(-) delete mode 100644 odb/exception.cxx diff --git a/odb/exception.cxx b/odb/exception.cxx deleted file mode 100644 index 330e70a..0000000 --- a/odb/exception.cxx +++ /dev/null @@ -1,17 +0,0 @@ -// file : odb/exception.cxx -// author : Boris Kolpackov -// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -#include - -namespace odb -{ - const char* exception:: - what () const throw () - { - return typeid (*this).name (); - } -} diff --git a/odb/exception.hxx b/odb/exception.hxx index 0ab188a..e0217b7 100644 --- a/odb/exception.hxx +++ b/odb/exception.hxx @@ -16,10 +16,8 @@ namespace odb { struct LIBODB_EXPORT exception: std::exception { - // By default return the exception type name ( typeid (*this).name () ). - // virtual const char* - what () const throw (); + what () const throw () = 0; }; } diff --git a/odb/exceptions.cxx b/odb/exceptions.cxx index d86657c..b27cc37 100644 --- a/odb/exceptions.cxx +++ b/odb/exceptions.cxx @@ -7,4 +7,39 @@ namespace odb { + const char* already_in_transaction:: + what () const throw () + { + return "transaction already in progress in this thread"; + } + + const char* not_in_transaction:: + what () const throw () + { + return "operation can only be performed in transaction"; + } + + const char* transaction_already_finilized:: + what () const throw () + { + return "transaction already committed or rolled back"; + } + + const char* deadlock:: + what () const throw () + { + return "transaction aborted due to deadlock"; + } + + const char* object_not_persistent:: + what () const throw () + { + return "object not persistent"; + } + + const char* object_already_persistent:: + what () const throw () + { + return "object already persistent"; + } } diff --git a/odb/exceptions.hxx b/odb/exceptions.hxx index ff97873..8c9e826 100644 --- a/odb/exceptions.hxx +++ b/odb/exceptions.hxx @@ -16,26 +16,38 @@ namespace odb { struct LIBODB_EXPORT already_in_transaction: odb::exception { + virtual const char* + what () const throw (); }; struct LIBODB_EXPORT not_in_transaction: odb::exception { + virtual const char* + what () const throw (); }; struct LIBODB_EXPORT transaction_already_finilized: odb::exception { + virtual const char* + what () const throw (); }; struct LIBODB_EXPORT deadlock: odb::exception { + virtual const char* + what () const throw (); }; struct LIBODB_EXPORT object_not_persistent: odb::exception { + virtual const char* + what () const throw (); }; struct LIBODB_EXPORT object_already_persistent: odb::exception { + virtual const char* + what () const throw (); }; struct LIBODB_EXPORT database_exception: odb::exception diff --git a/odb/makefile b/odb/makefile index 7197d82..15439da 100644 --- a/odb/makefile +++ b/odb/makefile @@ -6,7 +6,6 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make cxx := \ -exception.cxx \ exceptions.cxx \ database.cxx \ transaction.cxx -- cgit v1.1