From 6ca1c8ee64bf7268d194eb15e72d3024a335039d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 19 Sep 2009 08:20:12 +0200 Subject: Add root exception class Derive all other exceptions from it. --- cutl/compiler/code-stream.hxx | 6 ++++-- cutl/compiler/context.hxx | 5 +++-- cutl/compiler/type-info.hxx | 3 ++- cutl/container/any.hxx | 4 +++- cutl/container/graph.hxx | 6 ++++-- cutl/exception.cxx | 17 +++++++++++++++++ cutl/exception.hxx | 22 ++++++++++++++++++++++ cutl/fs/path.hxx | 4 +++- cutl/makefile | 2 +- cutl/shared-ptr/base.hxx | 7 ++++--- 10 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 cutl/exception.cxx create mode 100644 cutl/exception.hxx (limited to 'cutl') diff --git a/cutl/compiler/code-stream.hxx b/cutl/compiler/code-stream.hxx index bb8305a..a1a5d1a 100644 --- a/cutl/compiler/code-stream.hxx +++ b/cutl/compiler/code-stream.hxx @@ -9,6 +9,8 @@ #include // std::auto_ptr #include +#include + namespace cutl { namespace compiler @@ -54,8 +56,8 @@ namespace cutl typedef typename std::basic_streambuf::traits_type traits_type; typedef typename std::basic_streambuf::int_type int_type; - struct eof {}; - struct sync {}; + class eof: exception {}; + class sync: exception {}; public: from_streambuf_adapter (std::basic_streambuf& stream) diff --git a/cutl/compiler/context.hxx b/cutl/compiler/context.hxx index 4bae010..5f4eb1e 100644 --- a/cutl/compiler/context.hxx +++ b/cutl/compiler/context.hxx @@ -10,6 +10,7 @@ #include #include // std::size_t +#include #include namespace cutl @@ -19,8 +20,8 @@ namespace cutl class context { public: - struct no_entry {}; - struct typing {}; + struct no_entry: exception {}; + struct typing: exception {}; public: context () {} diff --git a/cutl/compiler/type-info.hxx b/cutl/compiler/type-info.hxx index f970067..9fa5593 100644 --- a/cutl/compiler/type-info.hxx +++ b/cutl/compiler/type-info.hxx @@ -10,6 +10,7 @@ #include #include // std::type_info +#include #include #include @@ -76,7 +77,7 @@ namespace cutl // // - class no_type_info {}; + class no_type_info: exception {}; type_info const& lookup (type_id const&); diff --git a/cutl/container/any.hxx b/cutl/container/any.hxx index 0c89a38..4fd05b5 100644 --- a/cutl/container/any.hxx +++ b/cutl/container/any.hxx @@ -9,6 +9,8 @@ #include // std::auto_ptr #include // std::type_info +#include + namespace cutl { namespace container @@ -16,7 +18,7 @@ namespace cutl class any { public: - struct typing {}; + struct typing: exception {}; public: template diff --git a/cutl/container/graph.hxx b/cutl/container/graph.hxx index 9d1c716..35650c1 100644 --- a/cutl/container/graph.hxx +++ b/cutl/container/graph.hxx @@ -7,12 +7,16 @@ #define CUTL_CONTAINER_GRAPH_HXX #include + +#include #include namespace cutl { namespace container { + struct no_edge: exception {}; + template class graph { @@ -20,8 +24,6 @@ namespace cutl typedef N node_base; typedef E edge_base; - struct no_edge {}; - public: template T& diff --git a/cutl/exception.cxx b/cutl/exception.cxx new file mode 100644 index 0000000..e8389f7 --- /dev/null +++ b/cutl/exception.cxx @@ -0,0 +1,17 @@ +// file : cutl/exception.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include + +#include + +namespace cutl +{ + char const* exception:: + what () const throw () + { + return typeid (*this).name (); + } +} diff --git a/cutl/exception.hxx b/cutl/exception.hxx new file mode 100644 index 0000000..242057b --- /dev/null +++ b/cutl/exception.hxx @@ -0,0 +1,22 @@ +// file : cutl/exception.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef CUTL_EXCEPTION_HXX +#define CUTL_EXCEPTION_HXX + +#include + +namespace cutl +{ + struct exception: std::exception + { + // By default return the exception type name ( typeid (*this).name () ). + // + virtual char const* + what () const throw (); + }; +} + +#endif // CUTL_EXCEPTION_HXX diff --git a/cutl/fs/path.hxx b/cutl/fs/path.hxx index a79fc5c..f310d55 100644 --- a/cutl/fs/path.hxx +++ b/cutl/fs/path.hxx @@ -9,11 +9,13 @@ #include #include +#include + namespace cutl { namespace fs { - struct invalid_path: std::exception + struct invalid_path: exception { virtual char const* what () const throw (); diff --git a/cutl/makefile b/cutl/makefile index f5adfce..294bbd5 100644 --- a/cutl/makefile +++ b/cutl/makefile @@ -5,7 +5,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make -cxx_tun := shared-ptr/base.cxx +cxx_tun := exception.cxx shared-ptr/base.cxx cxx_tun += fs/path.cxx diff --git a/cutl/shared-ptr/base.hxx b/cutl/shared-ptr/base.hxx index bb297cb..999c6d0 100644 --- a/cutl/shared-ptr/base.hxx +++ b/cutl/shared-ptr/base.hxx @@ -8,7 +8,8 @@ #include #include // std::size_t -#include // std::exception + +#include namespace cutl { @@ -36,7 +37,7 @@ operator delete (void*, cutl::share) throw (); namespace cutl { - struct not_shared: std::exception + struct not_shared: exception { virtual char const* what () const throw (); @@ -81,7 +82,7 @@ namespace cutl template inline std::size_t - ref_count (X const*); + ref_count (X const*); } #include -- cgit v1.1