libstdc++
exception.hpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the terms
00008 // of the GNU General Public License as published by the Free Software
00009 // Foundation; either version 3, or (at your option) any later
00010 // version.
00011 
00012 // This library is distributed in the hope that it will be useful, but
00013 // WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 // General Public License for more details.
00016 
00017 // Under Section 7 of GPL version 3, you are granted additional
00018 // permissions described in the GCC Runtime Library Exception, version
00019 // 3.1, as published by the Free Software Foundation.
00020 
00021 // You should have received a copy of the GNU General Public License and
00022 // a copy of the GCC Runtime Library Exception along with this program;
00023 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00024 // <http://www.gnu.org/licenses/>.
00025 
00026 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00027 
00028 // Permission to use, copy, modify, sell, and distribute this software
00029 // is hereby granted without fee, provided that the above copyright
00030 // notice appears in all copies, and that both that copyright notice
00031 // and this permission notice appear in supporting documentation. None
00032 // of the above authors, nor IBM Haifa Research Laboratories, make any
00033 // representation about the suitability of this software for any
00034 // purpose. It is provided "as is" without express or implied
00035 // warranty.
00036 
00037 /**
00038  * @file exception.hpp
00039  * Contains exception classes.
00040  */
00041 
00042 #ifndef PB_DS_EXCEPTION_HPP
00043 #define PB_DS_EXCEPTION_HPP
00044 
00045 #include <bits/c++config.h>
00046 #include <stdexcept>
00047 #include <cstdlib>
00048 
00049 namespace __gnu_pbds
00050 {
00051   /**
00052    *  @defgroup exceptions-pbds Exceptions
00053    *  @ingroup pbds
00054    *  @{
00055    */
00056 
00057   /// Base class for exceptions.
00058   struct container_error : public std::logic_error
00059   {
00060     container_error()
00061     : std::logic_error(__N("__gnu_pbds::container_error")) { }
00062   };
00063 
00064   /// An entry cannot be inserted into a container object for logical
00065   /// reasons (not, e.g., if memory is unabvailable, in which case
00066   /// the allocator_type's exception will be thrown).
00067   struct insert_error : public container_error { };
00068 
00069   /// A join cannot be performed logical reasons (i.e., the ranges of
00070   /// the two container objects being joined overlaps.
00071   struct join_error : public container_error { };
00072 
00073   /// A container cannot be resized.
00074   struct resize_error : public container_error { };
00075 
00076 #if __EXCEPTIONS
00077   inline void
00078   __throw_container_error(void)
00079   { throw container_error(); }
00080 
00081   inline void
00082   __throw_insert_error(void)
00083   { throw insert_error(); }
00084 
00085   inline void
00086   __throw_join_error(void)
00087   { throw join_error(); }
00088 
00089   inline void
00090   __throw_resize_error(void)
00091   { throw resize_error(); }
00092 #else
00093   inline void
00094   __throw_container_error(void)
00095   { std::abort(); }
00096 
00097   inline void
00098   __throw_insert_error(void)
00099   { std::abort(); }
00100 
00101   inline void
00102   __throw_join_error(void)
00103   { std::abort(); }
00104 
00105   inline void
00106   __throw_resize_error(void)
00107   { std::abort(); }
00108 #endif
00109   //@}
00110 } // namespace __gnu_pbds
00111 
00112 #endif