ArgException.h

Go to the documentation of this file.
00001 
00002 /****************************************************************************** 
00003  * 
00004  *  file:  ArgException.h
00005  * 
00006  *  Copyright (c) 2003, Michael E. Smoot .
00007  *  All rights reverved.
00008  * 
00009  *  See the file COPYING in the top directory of this distribution for
00010  *  more information.
00011  *  
00012  *  THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 
00013  *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
00014  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
00015  *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
00016  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
00017  *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
00018  *  DEALINGS IN THE SOFTWARE.  
00019  *  
00020  *****************************************************************************/ 
00021 
00022 
00023 #ifndef TCLAP_ARG_EXCEPTION_H
00024 #define TCLAP_ARG_EXCEPTION_H
00025 
00026 #include <string>
00027 #include <exception>
00028 
00029 namespace TCLAP {
00030 
00035 class ArgException : public std::exception
00036 {
00037      public:
00038      
00046           ArgException( const std::string& text = "undefined exception", 
00047                            const std::string& id = "undefined",
00048                            const std::string& td = "Generic ArgException")
00049                : std::exception(), 
00050                  _errorText(text), 
00051                  _argId( id ), 
00052                  _typeDescription(td)
00053           { } 
00054           
00058           virtual ~ArgException() throw() { }
00059 
00063           std::string error() const { return ( _errorText ); }
00064 
00068           std::string argId() const  
00069           { 
00070                if ( _argId == "undefined" )
00071                     return " ";
00072                else
00073                     return ( "Argument: " + _argId ); 
00074           }
00075 
00079           const char* what() const throw() 
00080           {
00081                std::string ex = _argId + " -- " + _errorText;
00082                return ex.c_str();
00083           }
00084 
00089           std::string typeDescription() const
00090           {
00091                return _typeDescription; 
00092           }
00093 
00094 
00095      private:
00096 
00100           std::string _errorText;
00101 
00105           std::string _argId;
00106 
00111           std::string _typeDescription;
00112 
00113 };
00114 
00119 class ArgParseException : public ArgException
00120 { 
00121      public:
00128           ArgParseException( const std::string& text = "undefined exception", 
00129                                 const std::string& id = "undefined" )
00130                : ArgException( text, 
00131                                id, 
00132                                    std::string( "Exception found while parsing " ) + 
00133                                    std::string( "the value the Arg has been passed." ))
00134                { }
00135 };
00136 
00141 class CmdLineParseException : public ArgException
00142 {
00143      public:
00150           CmdLineParseException( const std::string& text = "undefined exception", 
00151                                     const std::string& id = "undefined" )
00152                : ArgException( text, 
00153                                id,
00154                                    std::string( "Exception found when the values ") +
00155                                    std::string( "on the command line do not meet ") +
00156                                    std::string( "the requirements of the defined ") +
00157                                    std::string( "Args." ))
00158           { }
00159 };
00160 
00165 class SpecificationException : public ArgException
00166 {
00167      public:
00174           SpecificationException( const std::string& text = "undefined exception",
00175                                      const std::string& id = "undefined" )
00176                : ArgException( text, 
00177                                id,
00178                                    std::string("Exception found when an Arg object ")+
00179                                    std::string("is improperly defined by the ") +
00180                                    std::string("developer." )) 
00181           { }
00182 
00183 };
00184 
00185 } // namespace TCLAP
00186 
00187 #endif
00188 

Generated on Sun Mar 11 15:33:24 2007 for MetalWarriors by  doxygen 1.4.7