exception.hpp revision 169691
12116Sjkh// -*- C++ -*-
22116Sjkh
32116Sjkh// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
42116Sjkh//
52116Sjkh// This file is part of the GNU ISO C++ Library.  This library is free
62116Sjkh// software; you can redistribute it and/or modify it under the terms
72116Sjkh// of the GNU General Public License as published by the Free Software
82116Sjkh// Foundation; either version 2, or (at your option) any later
92116Sjkh// version.
102116Sjkh
118870Srgrimes// This library is distributed in the hope that it will be useful, but
122116Sjkh// WITHOUT ANY WARRANTY; without even the implied warranty of
132116Sjkh// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
142116Sjkh// General Public License for more details.
152116Sjkh
162116Sjkh// You should have received a copy of the GNU General Public License
178870Srgrimes// along with this library; see the file COPYING.  If not, write to
182116Sjkh// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
192116Sjkh// MA 02111-1307, USA.
202116Sjkh
212116Sjkh// As a special exception, you may use this file as part of a free
222116Sjkh// software library without restriction.  Specifically, if other files
232116Sjkh// instantiate templates or use macros or inline functions from this
242116Sjkh// file, or you compile this file and link it with other files to
252116Sjkh// produce an executable, this file does not by itself cause the
262116Sjkh// resulting executable to be covered by the GNU General Public
272116Sjkh// License.  This exception does not however invalidate any other
282116Sjkh// reasons why the executable file might be covered by the GNU General
292116Sjkh// Public License.
302116Sjkh
312116Sjkh// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
322116Sjkh
332116Sjkh// Permission to use, copy, modify, sell, and distribute this software
342116Sjkh// is hereby granted without fee, provided that the above copyright
352116Sjkh// notice appears in all copies, and that both that copyright notice
362116Sjkh// and this permission notice appear in supporting documentation. None
378870Srgrimes// of the above authors, nor IBM Haifa Research Laboratories, make any
382116Sjkh// representation about the suitability of this software for any
392116Sjkh// purpose. It is provided "as is" without express or implied
402116Sjkh// warranty.
412116Sjkh
422116Sjkh/**
432116Sjkh * @file exception.hpp
448870Srgrimes * Contains exception classes.
452116Sjkh */
462116Sjkh
478870Srgrimes#ifndef PB_DS_EXCEPTION_HPP
482116Sjkh#define PB_DS_EXCEPTION_HPP
492116Sjkh
502116Sjkh#include <stdexcept>
512116Sjkh
522116Sjkhnamespace pb_ds
532116Sjkh{
542116Sjkh  // Base class for exceptions.
552116Sjkh  struct container_error : public std::logic_error
562116Sjkh  {
572116Sjkh    container_error()
582116Sjkh    : std::logic_error(__N("pb_ds::container_error")) { }
592116Sjkh  };
602116Sjkh
612116Sjkh  // An entry cannot be inserted into a container object for logical
622116Sjkh  // reasons (not, e.g., if memory is unabvailable, in which case
632116Sjkh  // the allocator's exception will be thrown).
642116Sjkh  struct insert_error : public container_error { };
652116Sjkh
662116Sjkh  // A join cannot be performed logical reasons (i.e., the ranges of
672116Sjkh  // the two container objects being joined overlaps.
682116Sjkh  struct join_error : public container_error { };
692116Sjkh
702116Sjkh  // A container cannot be resized.
712116Sjkh  struct resize_error : public container_error { };
728870Srgrimes
738870Srgrimes#if __EXCEPTIONS
748870Srgrimes  void
758870Srgrimes  __throw_container_error(void)
768870Srgrimes  { throw container_error(); }
778870Srgrimes
782116Sjkh  void
792116Sjkh  __throw_insert_error(void)
802116Sjkh  { throw insert_error(); }
812116Sjkh
822116Sjkh  void
832116Sjkh  __throw_join_error(void)
842116Sjkh  { throw join_error(); }
852116Sjkh
862116Sjkh  void
872116Sjkh  __throw_resize_error(void)
882116Sjkh  { throw resize_error(); }
892116Sjkh#else
902116Sjkh  void
912116Sjkh  __throw_container_error(void)
922116Sjkh  { std::abort(); }
932116Sjkh
942116Sjkh  void
952116Sjkh  __throw_insert_error(void)
962116Sjkh  { std::abort(); }
972116Sjkh
98  void
99  __throw_join_error(void)
100  { std::abort(); }
101
102  void
103  __throw_resize_error(void)
104  { std::abort(); }
105#endif
106} // namespace pb_ds
107
108#endif
109