#ifndef _GATS_EXCEPTION_H_ #define _GATS_EXCEPTION_H_ /** @file GATS_Exception.h @brief Header file for the base class for exceptions thrown by this API. @date $Date: 2007-01-10 11:06:55 -0500 (Wed, 10 Jan 2007) $ @version $Rev$ @author - Lance Deaver @copyright (©) Copyright 2006 by GATS Inc. 11864 Canon Blvd., Suite 101, Newport News, VA 23606 All Rights Reserved. No part of this software or publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise without the prior written permission of GATS Inc. @see GATS_Exception @todo Add an EXPORT macro so windows users can preface functions with the decspl wen constructing DLL files. @bug None known $Id$ */ #include #include #ifdef __linux__ #include #endif class GATS_Exception; //forward declaration /** * @relates GATS_Exception * @brief Overloaded std::ostream << operator that works on GATS_Exception objects. */ std::ostream& operator<<( std::ostream&, const GATS_Exception&); class GATS_Exception : virtual public std::exception { public: friend std::ostream& operator<<( std::ostream&, const GATS_Exception&); /** * @brief GATS_Exception copy constructor. */ GATS_Exception(const GATS_Exception& e) throw(); /** * @brief Destroy the GATS_Exception object. */ virtual ~GATS_Exception() throw(); /** * @brief GATS_Exception assignment operator. */ GATS_Exception& operator=(const GATS_Exception& rhs) throw(); /** * @brief Return the exception message. */ virtual const char* what() const throw() { return what_.c_str(); } /** * @brief Return the source filename where exception was thrown. */ virtual const char* GetFilename() const throw() { return filename_; } /** * @brief Return the line number from the source file where exception was thrown */ virtual unsigned int GetLineNumber() const throw() { return linenumber_ ; } /** * @brief Return the Stack trace (available on linux only) */ virtual std::string StackTrace() const throw(); protected: /** * @brief Defines how the data is printed when using the overloaded << operator. */ virtual void PrintOn(std::ostream& o) const; /** * @brief The GATS_Exception constructor */ GATS_Exception(const char* w, const char* filename, const unsigned int linenumber) throw(); private: std::string what_; const char* filename_; unsigned int linenumber_; #ifdef __linux__ std::vector stack_; #endif }; /** * @def THROW_GATS_EXCEPTION(objectname,message) * Throw an exception object that was derived from GATS_Exception. * * @param[in] objectname The name of an object derived from GATS_Exception. * @param[in] message A const char* string containing an informative message explaining the exception * * @note This macro automagically appends the filename * and the linenumber to the constructor of the object. * * @warning Do not place \a objectname inside quotation marks. */ #define THROW_GATS_EXCEPTION(objectname, message) throw objectname(message, __FILE__, __LINE__) // Some execption classes derived from GATS_Exception /** * The BadTypeConversion object is thrown if errors were encountered * during a conversion from one data type into a std::string and vise versa. */ class BadTypeConversion : public GATS_Exception { public: /** * @brief BadTypeConversion constructor */ BadTypeConversion(const std::string& msg, const char* filename, const unsigned int linenumber) : GATS_Exception(msg.c_str(),filename,linenumber) {} }; /** * The ArrayNotMonotonic object is thrown if an array * or vector fails a test for monotonicity. i.e. The values need to be monotonically * increasing or decreasing. */ class ArrayNotMonotonic : public GATS_Exception { public: /** * @brief ArrayNotMonotonic constructor */ ArrayNotMonotonic(const std::string& msg, const char* filename, const unsigned int linenumber) : GATS_Exception(msg.c_str(),filename,linenumber) {} }; /** * The ZeroLengthArray object is thrown if an array or vector is zero length. */ class ZeroLengthArray : public GATS_Exception { public: /** * @brief ZeroLengthArray constructor */ ZeroLengthArray(const std::string& msg, const char* filename, const unsigned int linenumber) : GATS_Exception(msg.c_str(),filename,linenumber) {} }; /** * The InvalidArrayLength object is thrown if an array or vector does not have the correct number of elements. */ class InvalidArrayLength : public GATS_Exception { public: /** * @brief InvalidArrayLength constructor */ InvalidArrayLength(const std::string& msg, const char* filename, const unsigned int linenumber) : GATS_Exception(msg.c_str(),filename,linenumber) {} }; /** * The CanNotOpenFile object is thrown if an error occured when trying to open a file. */ class CanNotOpenFile : public GATS_Exception { public: /** * @brief CanNotOpenFile constructor */ CanNotOpenFile(const std::string& msg, const char* filename, const unsigned int linenumber) : GATS_Exception(msg.c_str(),filename,linenumber) {} }; /** * The ValueOutOfRange object is thrown if an input value is outside of allowed limits. */ class ValueOutOfRange : public GATS_Exception { public: /** * @brief ValueOutOfRange constructor */ ValueOutOfRange(const std::string& msg, const char* filename, const unsigned int linenumber) : GATS_Exception(msg.c_str(),filename,linenumber) {} }; #endif //_GATS_EXCEPTION_H_