00001 /***************************************************************************
00002 * This file is part of the MagiC++ library. *
00003 * *
00004 * Copyright (C) 1998-2001 Marko Grönroos <magi@iki.fi> *
00005 * *
00006 ***************************************************************************
00007 * *
00008 * This library is free software; you can redistribute it and/or *
00009 * modify it under the terms of the GNU Library General Public *
00010 * License as published by the Free Software Foundation; either *
00011 * version 2 of the License, or (at your option) any later version. *
00012 * *
00013 * This library is distributed in the hope that it will be useful, *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
00016 * Library General Public License for more details. *
00017 * *
00018 * You should have received a copy of the GNU Library General Public *
00019 * License along with this library; see the file COPYING.LIB. If *
00020 * not, write to the Free Software Foundation, Inc., 59 Temple Place *
00021 * - Suite 330, Boston, MA 02111-1307, USA. *
00022 * *
00023 ***************************************************************************/
00024
00025 #ifndef __MAGIC_MEXCEPTION_H__
00026 #define __MAGIC_MEXCEPTION_H__
00027
00028 #include "magic/mobject.h"
00029
00030 namespace MagiC {
00031 class String;
00032 }
00033 using namespace MagiC;
00034
00036 // Exception handling macros
00037
00051 class Exception : public Object {
00052 String* mWhat;
00053 public:
00054
00061 Exception (const String& what);
00062 Exception (const Exception& orig);
00063 ~Exception ();
00064
00067 const String& what () const {return *mWhat;}
00068 };
00069
00070 #define EXCEPTIONCLASS(eclass) \
00071 class eclass : public Exception {\
00072 public:\
00073 eclass (const String& what_arg) : Exception (what_arg) { }\
00074 virtual ~eclass () {;}\
00075 };
00076
00077 // eclass (const __string& what_arg): logic_error (what_arg) {;}
00078
00079 EXCEPTIONCLASS (generic_exception);
00080 EXCEPTIONCLASS (invalid_format);
00081 EXCEPTIONCLASS (assertion_failed);
00082 EXCEPTIONCLASS (forwarded_failure);
00083 EXCEPTIONCLASS (file_not_found);
00084 EXCEPTIONCLASS (check_failed);
00085 EXCEPTIONCLASS (out_of_bounds);
00086 EXCEPTIONCLASS (out_of_range);
00087 EXCEPTIONCLASS (runtime_error);
00088
00092 #define failtrace(expr) try {expr;} catch (Exception e) {throw forwarded_failure (format ("%s\n%%ERR: Exception forwaded at %s[%d]:%s()", (CONSTR) e.what(), __FILE__, __LINE__, __FUNCTION__));}
00093 #define FAILTRACE failtrace
00094
00099 #define trywith(expr,err) try {expr;} catch (Exception e) {throw forwarded_failure (format ("%s\n%%ERR: Exception forwaded at %s[%d]:%s()\n%%ERR: %s", (CONSTR) e.what(), __FILE__, __LINE__, __FUNCTION__, (CONSTR) err));}
00100 #define TRYWITH trywith
00101
00102
00103 #endif
1.2.6 written by Dimitri van Heesch,
© 1997-2001