diff --git a/qse/include/qse/Exception.hpp b/qse/include/qse/Exception.hpp new file mode 100644 index 00000000..56b03eee --- /dev/null +++ b/qse/include/qse/Exception.hpp @@ -0,0 +1,88 @@ +/* + * $Id$ + * + Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef _QSE_EXCEPTION_CLASS_ +#define _QSE_EXCEPTION_CLASS_ + +#include +#include + +///////////////////////////////// +QSE_BEGIN_NAMESPACE(QSE) +///////////////////////////////// + +class Exception +{ +public: + Exception ( + const qse_char_t* name, const qse_char_t* msg, + const qse_char_t* file, int line): + name(name), msg(msg) +#if !defined(QSE_NO_LOCATION_IN_EXCEPTION) + , file(file), line(line) +#endif + { + } + + const qse_char_t* name; + const qse_char_t* msg; +#if !defined(QSE_NO_LOCATION_IN_EXCEPTION) + const qse_char_t* file; + int line; +#endif +}; + +#define QSE_THROW(ex_name) \ + throw ex_name(QSE_Q(ex_name),QSE_Q(ex_name), QSE_T(__FILE__), __LINE__) +#define QSE_THROW_WITH_MSG(ex_name,msg) \ + throw ex_name(QSE_Q(ex_name),msg, QSE_T(__FILE__), __LINE__) + +#define QSE_EXCEPTION(ex_name) \ + class ex_name: public QSE::Exception \ + { \ + public: \ + ex_name (const qse_char_t* name, const qse_char_t* msg, \ + const qse_char_t* file, int line): \ + QSE::Exception (name, msg, file, line) {} \ + } + +#define QSE_EXCEPTION_NAME(exception_object) ((exception_object).name) +#define QSE_EXCEPTION_MSG(exception_object) ((exception_object).msg) + +#if !defined(QSE_NO_LOCATION_IN_EXCEPTION) +# define QSE_EXCEPTION_FILE(exception_object) ((exception_object).file) +# define QSE_EXCEPTION_LINE(exception_object) ((exception_object).line) +#else +# define QSE_EXCEPTION_FILE(exception_object) (QSE_T("")) +# define QSE_EXCEPTION_LINE(exception_object) (0) +#endif + +///////////////////////////////// +QSE_END_NAMESPACE(QSE) +///////////////////////////////// + +#endif diff --git a/qse/include/qse/Makefile.am b/qse/include/qse/Makefile.am index a6e4d808..897a9aeb 100644 --- a/qse/include/qse/Makefile.am +++ b/qse/include/qse/Makefile.am @@ -9,7 +9,7 @@ pkginclude_HEADERS = \ if ENABLE_CXX pkginclude_HEADERS += \ Types.hpp Hashable.hpp Uncopyable.hpp RefCounted.hpp \ - ScopedPtr.hpp + ScopedPtr.hpp Exception.hpp endif install-data-hook: diff --git a/qse/include/qse/Makefile.in b/qse/include/qse/Makefile.in index ad23e931..279625c7 100644 --- a/qse/include/qse/Makefile.in +++ b/qse/include/qse/Makefile.in @@ -52,7 +52,7 @@ build_triplet = @build@ host_triplet = @host@ @ENABLE_CXX_TRUE@am__append_1 = \ @ENABLE_CXX_TRUE@ Types.hpp Hashable.hpp Uncopyable.hpp RefCounted.hpp \ -@ENABLE_CXX_TRUE@ ScopedPtr.hpp +@ENABLE_CXX_TRUE@ ScopedPtr.hpp Exception.hpp subdir = include/qse DIST_COMMON = $(am__pkginclude_HEADERS_DIST) $(srcdir)/Makefile.am \ @@ -95,7 +95,7 @@ am__can_run_installinfo = \ am__pkginclude_HEADERS_DIST = conf-msw.h conf-os2.h conf-dos.h \ conf-vms.h conf-mac.h conf-inf.h types.h macros.h pack1.h \ unpack.h Types.hpp Hashable.hpp Uncopyable.hpp RefCounted.hpp \ - ScopedPtr.hpp + ScopedPtr.hpp Exception.hpp am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ diff --git a/qse/include/qse/cmn/ExcMmgr.hpp b/qse/include/qse/cmn/ExcMmgr.hpp index 884a185b..c6c1e1ea 100644 --- a/qse/include/qse/cmn/ExcMmgr.hpp +++ b/qse/include/qse/cmn/ExcMmgr.hpp @@ -24,10 +24,11 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _QSE_CMN_STDMMGR_HPP_ -#define _QSE_CMN_STDMMGR_HPP_ +#ifndef _QSE_CMN_EXCMMGR_HPP_ +#define _QSE_CMN_EXCMMGR_HPP_ #include +#include ///////////////////////////////// QSE_BEGIN_NAMESPACE(QSE) @@ -45,6 +46,8 @@ public: void freeMem (void* ptr); static ExcMmgr* getDFL(); + + QSE_EXCEPTION (Error); }; ///////////////////////////////// diff --git a/qse/include/qse/cmn/Mmged.hpp b/qse/include/qse/cmn/Mmged.hpp index e8a96182..155c4a83 100644 --- a/qse/include/qse/cmn/Mmged.hpp +++ b/qse/include/qse/cmn/Mmged.hpp @@ -35,7 +35,7 @@ QSE_BEGIN_NAMESPACE(QSE) /// /// The Mmged class defines a memory manager interface to be inherited by -/// a subclass that uses a memory manager. +/// a subclass that uses a memory manager. /// class QSE_EXPORT Mmged @@ -48,9 +48,6 @@ public: /// Mmgr* getMmgr () const { return this->mmgr; } - - - protected: Mmgr* mmgr; }; diff --git a/qse/lib/cmn/ExcMmgr.cpp b/qse/lib/cmn/ExcMmgr.cpp index a3349d41..81cd58dd 100644 --- a/qse/lib/cmn/ExcMmgr.cpp +++ b/qse/lib/cmn/ExcMmgr.cpp @@ -36,14 +36,14 @@ QSE_BEGIN_NAMESPACE(QSE) void* ExcMmgr::allocMem (qse_size_t n) { void* ptr = ::malloc (n); - if (!ptr) throw 1; // TODO: change 1 to a proper exception object + if (!ptr) QSE_THROW (Error); return ptr; } void* ExcMmgr::reallocMem (void* ptr, qse_size_t n) { void* xptr = ::realloc (ptr, n); - if (!xptr) throw 1; + if (!xptr) QSE_THROW (Error); return xptr; }