Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

Exception.h (Maintainer: Marc Sturm)

Go to the documentation of this file.
00001 // -*- mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // --------------------------------------------------------------------------
00005 //                   OpenMS Mass Spectrometry Framework 
00006 // --------------------------------------------------------------------------
00007 //  Copyright (C) 2003-2008 -- Oliver Kohlbacher, Knut Reinert
00008 //
00009 //  This library is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU Lesser General Public
00011 //  License as published by the Free Software Foundation; either
00012 //  version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //  This library is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //  Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with this library; if not, write to the Free Software
00021 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // --------------------------------------------------------------------------
00024 // $Maintainer: Marc Sturm $
00025 // --------------------------------------------------------------------------
00026 
00027 #ifndef OPENMS_CONCEPT_EXCEPTION_H
00028 #define OPENMS_CONCEPT_EXCEPTION_H
00029 
00030 #include <OpenMS/config.h>
00031 #include <OpenMS/CONCEPT/Types.h>
00032 
00033 #include <new>
00034 #include <string>
00035 #include <sstream>
00036 
00037 namespace OpenMS 
00038 {
00039 
00054   namespace Exception 
00055   {
00056     
00088     class Base 
00089       : public std::exception
00090     {
00091       public:
00092 
00096 
00098       Base()
00099         throw();
00100       
00102       Base(const char* file, int line, const char* function)
00103         throw();
00104 
00106       Base
00107         (const char* file, int line, const char* function, const std::string& name , const std::string& message)
00108         throw();
00109 
00111       Base(const Base& exception)
00112         throw();
00113 
00115       virtual ~Base() throw();
00117 
00121   
00123       const char* getName() const
00124         throw();
00125 
00127       virtual const char* what() const
00128         throw();
00129 
00131       int getLine() const
00132         throw();
00133   
00135       const char* getFile() const
00136         throw();
00137 
00139       const char* getFunction() const
00140         throw();
00141 
00143       const char* getMessage() const
00144         throw();
00145 
00147       void setMessage(const std::string& message)
00148         throw();
00149 
00151 
00152       protected:
00154       const char* file_;
00155 
00157       int         line_;
00158 
00160       const char* function_;
00161         
00163       std::string name_;
00164       
00166       std::string what_;
00167     };    
00168 
00176     class Precondition
00177       : public Base
00178     {
00179       public:
00181       Precondition(const char* file, int line, const char* function, const std::string& condition)  throw();
00182     };
00183 
00191     class Postcondition
00192       : public Base
00193     {
00194       public:
00196       Postcondition(const char* file, int line, const char* function, const std::string& condition) throw();
00197     };
00198 
00207     class MissingInformation
00208       : public Base
00209     {
00210       public:
00211         MissingInformation(const char* file, int line, const char* function, const std::string& error_message) throw();
00212     };
00213 
00214 
00228     class IndexUnderflow 
00229       : public Base
00230     {
00231       public:
00232 
00233       IndexUnderflow(const char* file, int line, const char* function, Int index = 0, UInt size = 0)
00234         throw();
00235 
00236 
00237       protected:
00238 
00239       UInt size_;
00240       Int index_;
00241     };
00242 
00255     class SizeUnderflow 
00256       : public Base
00257     {
00258       public:
00259 
00260       SizeUnderflow(const char* file, int line, const char* function, UInt size = 0)
00261         throw();
00262 
00263       protected:
00264       UInt size_;
00265     };
00266 
00279     class IndexOverflow 
00280       : public Base
00281     {
00282       public:
00283       IndexOverflow(const char* file, int line, const char* function, Int index = 0, UInt size = 0)
00284         throw();
00285 
00286       protected:
00287 
00288       UInt size_;
00289       Int index_;
00290     };
00291 
00299     class InvalidRange 
00300       : public Base
00301     {
00302       public:
00303       InvalidRange(const char* file, int line, const char* function)
00304         throw();
00305     };
00306 
00307 
00318     class InvalidSize 
00319       : public Base
00320     {
00321       public:
00322 
00323       InvalidSize(const char* file, int line, const char* function, UInt size = 0)
00324         throw();
00325 
00326       protected:
00327       UInt size_;
00328     };
00329 
00330 
00339     class OutOfRange 
00340       : public Base
00341     {
00342       public:
00343       OutOfRange(const char* file, int line, const char* function)
00344         throw();
00345     };
00346 
00356     class InvalidValue 
00357       : public Base
00358     {
00359       public:
00360         InvalidValue(const char* file, int line, const char* function, const std::string& message ,const std::string& value) throw();
00361     };
00362 
00368     class InvalidParameter 
00369       : public Base
00370     {
00371       public:
00372         InvalidParameter(const char* file, int line, const char* function, const std::string& message) throw();
00373     };
00374 
00383     class ConversionError 
00384       : public Base
00385     {
00386       public:
00387       ConversionError(const char* file, int line, const char* function, const std::string& error)
00388         throw();
00389       
00390       ~ConversionError()
00391         throw();
00392     };
00393 
00403     class IllegalSelfOperation
00404       : public Base
00405     {
00406       public:
00407       IllegalSelfOperation(const char* file, int line, const char* function)
00408         throw();
00409     };
00410 
00419     class NullPointer 
00420       : public Base
00421     {
00422       public:
00423       NullPointer(const char* file, int line, const char* function)
00424         throw();
00425     };
00426 
00434     class InvalidIterator
00435       : public Base
00436     {
00437       public:
00438       InvalidIterator(const char* file, int line, const char* function)
00439         throw();
00440     };
00441 
00450     class IncompatibleIterators
00451       : public Base
00452     {
00453       public:
00454       IncompatibleIterators(const char* file, int line, const char* function)
00455         throw();
00456     };
00457 
00468     class NotImplemented
00469       : public Base
00470     {
00471       public:
00472       NotImplemented(const char* file, int line, const char* function)
00473         throw();
00474     };
00475 
00483     class IllegalTreeOperation
00484       : public Base
00485     {
00486       public:
00487       IllegalTreeOperation(const char* file, int line, const char* function)
00488         throw();
00489     };
00490 
00501     class OutOfMemory
00502       : public Base, public std::bad_alloc
00503     {
00504       public:
00505       OutOfMemory(const char* file, int line, const char* function, UInt size = 0)
00506         throw();
00507       
00508       virtual ~OutOfMemory() 
00509         throw();
00510 
00511       protected:
00512       UInt size_;
00513     };
00514 
00520     class BufferOverflow 
00521       : public Base
00522     {
00523       public:
00524       BufferOverflow(const char* file, int line, const char* function)
00525         throw();
00526     };
00527 
00533     class DivisionByZero 
00534       : public Base
00535     {
00536       public:
00537       DivisionByZero(const char* file, int line, const char* function)
00538         throw();
00539     };
00540 
00546     class OutOfGrid 
00547       : public Base
00548     {
00549       public:
00550       OutOfGrid(const char* file, int line, const char* function)
00551         throw();
00552     };
00553 
00561     class FileNotFound 
00562       : public Base
00563     {
00564       public:
00565       FileNotFound(const char* file, int line, const char* function, const std::string& filename)
00566         throw();
00567 
00568       ~FileNotFound()
00569         throw();
00570       std::string getFilename() const
00571         throw();
00572 
00573       protected:
00574       std::string filename_;
00575     };
00576 
00584     class FileNotReadable 
00585       : public Base
00586     {
00587       public:
00588       FileNotReadable(const char* file, int line, const char* function, const std::string& filename)
00589         throw();
00590 
00591       ~FileNotReadable()
00592         throw();
00593       std::string getFilename() const
00594         throw();
00595 
00596       protected:
00597       std::string filename_;
00598     };
00599 
00607     class FileEmpty 
00608       : public Base
00609     {
00610       public:
00611       FileEmpty(const char* file, int line, const char* function, const std::string& filename)
00612         throw();
00613 
00614       ~FileEmpty()
00615         throw();
00616       std::string getFilename() const
00617         throw();
00618 
00619       protected:
00620       std::string filename_;
00621     };
00622 
00630     class IllegalPosition 
00631       : public Base
00632     {
00633       public:
00634       IllegalPosition(const char* file, int line, const char* function, float x, float y, float z)
00635         throw();
00636     };
00637 
00645     class ParseError
00646       : public Base
00647     {
00648       public:
00649       ParseError(const char* file, int line, const char* function, const std::string& expression,
00650           const std::string& message)
00651         throw();
00652     };
00653 
00661     class UnableToCreateFile
00662       : public Base
00663     {
00664       public:
00665       UnableToCreateFile(const char* file, int line, const char* function, const std::string& filename)
00666         throw();
00667 
00668       ~UnableToCreateFile()
00669         throw();
00670       std::string getFilename() const
00671         throw();
00672 
00673       protected:
00674       std::string filename_;
00675     };
00676     
00681     class IllegalArgument 
00682       : public Base
00683     {
00684     public:
00685 
00686       IllegalArgument(const char* file, int line, const char* function, const char* argument = "unknown") throw();
00687 
00688       ~IllegalArgument() throw();
00689 
00690     };
00691 
00692 
00693 
00701     class GlobalExceptionHandler
00702     {
00703       public:
00707 
00724       GlobalExceptionHandler()
00725         throw();
00727       
00731         
00734       static void setName(const std::string& name)
00735         throw();
00736         
00739       static void setMessage(const std::string& message)
00740         throw();
00741 
00744       static void setLine(int line)
00745         throw();
00746 
00749       static void setFile(const std::string& file)
00750         throw();
00751 
00754       static void setFunction(const std::string& function)
00755         throw();
00756 
00759       static void set
00760         (const std::string& file, int line, const std::string& function,
00761          const std::string& name, const std::string& message)
00762         throw();
00764       
00765       protected:
00766 
00768       static void terminate()
00769         throw();
00770 
00772       static void newHandler()
00773         throw(OutOfMemory);
00774 
00775       static std::string file_;
00776       static int         line_;
00777       static std::string function_;
00778       static std::string name_;
00779       static std::string what_;
00780     };
00781 
00784     extern GlobalExceptionHandler globalHandler;
00785 
00786 
00787 
00795     template <class T>
00796     class ElementNotFound
00797       : public Base
00798     {
00799       public:
00800       ElementNotFound(const char* file, int line, const char* function, const T& element) throw()
00801         : Base(file, line, function, "ElementNotFound", ""),
00802           element_(element)
00803       {
00804         std::stringstream s;
00805         s << element_;
00806         what_ = "the element " + s.str() + " could not be found";
00807         globalHandler.setMessage(what_);
00808       }
00809 
00810       ~ElementNotFound() throw()
00811       {
00812       }
00813       
00814       T getElement() const throw()
00815       {
00816         return element_;
00817       }
00818 
00819       protected:
00820       T element_;
00821     };
00822 
00823 
00824   }
00844     std::ostream& operator << (std::ostream& os, const Exception::Base& e);
00845   
00846 } // namespace OPENMS
00847 
00848 #endif // OPENMS_CONCEPT_EXCEPTION_H

Generated Tue Apr 1 15:36:34 2008 -- using doxygen 1.5.4 OpenMS / TOPP 1.1