exception.h

00001 /* -- 2007-05-07 -- 
00002  *  ardev - an augmented reality library for robot developers
00003  *  Copyright 2005-2007 - Toby Collett (ardev _at_ plan9.net.nz)
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Lesser General Public
00016  *  License along with this library; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
00018  *
00019  */
00020 #ifndef ARIDE_EXCEPTION_H
00021 #define ARIDE_EXCEPTION_H
00022 
00023 #include <stdio.h>
00024 #include <stdexcept>
00025 
00026 /* For each entry in exception type make sure and entry is added in Exception string in aride_exception.cpp
00027    Also make sure that ARIDE_UNKNOWN_EXCEPTION is the last entry in the enumeration */
00028 enum ExceptionType
00029 {
00030         ARDEV_FATAL_EXCEPTION,
00031         ARDEV_NO_FILE_SPECIFIED,
00032         ARDEV_FILE_NOT_FOUND,
00033         ARDEV_XML_PARSE_FAILED,
00034         ARDEV_ALLOC_ERROR,
00035         ARDEV_FILE_OPEN_FAILED,
00036         ARDEV_BAD_PARAMETER,
00037         ARDEV_NO_HANDLER,
00038         ARDEV_CLASS_NOT_FOUND,
00039         ARDEV_BAD_GUID,
00040         
00041         ARDEV_UNKNOWN_EXCEPTION
00042 };
00043 
00044 extern const char * ExceptionString[];
00045 
00046 class aride_exception : public std::runtime_error
00047 {
00048         public:
00049                 aride_exception(ExceptionType _Type,const char* _Function="",int _Line=0,void * _Extra=NULL) 
00050                         : std::runtime_error(ExceptionString[Type])
00051                 {
00052                         Type=_Type;
00053                         Function=_Function;
00054                         Line=_Line;
00055                         Extra=_Extra;
00056                 };
00057         
00058                 ExceptionType Type;
00059                 const char * Function;
00060                 int Line;
00061         
00062                 void * Extra;
00063         
00064                 const void Print() const
00065                 {
00066                         if (Type >= ARDEV_FATAL_EXCEPTION && Type < ARDEV_UNKNOWN_EXCEPTION)
00067                                 fprintf(stderr,"Exception %d in %s:%d. %s\n",Type,Function,Line,ExceptionString[Type]);
00068                         else
00069                                 fprintf(stderr,"Exception %d in %s:%d. Unknown Exception\n",Type,Function,Line);
00070                 };
00071 };
00072 
00073 #endif

SourceForge.net Logo Generated on Sat May 12 15:25:43 2007 for ardev by doxygen 1.5.1