/* This file is part of cardwords
   (c) 1998 1999 2000 Tobias Peters
   see file COPYING for the copyright terms.
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// cardwords_exceptions.hh

#ifndef CARDWORDS_EXCEPTIONS_HH
#define CARDWORDS_EXCEPTIONS_HH
#include "cardwords_gettext.hh"
#include <string>
class ostream;

namespace CardWords {
// Defining some types here that indicate exceptional states

// They are all derived from:
class Exception
{
public:
  virtual
  void
  print(ostream &) const = 0;
  virtual
  ~Exception();
};
}

ostream &
operator << (ostream & o, const CardWords::Exception & x);

namespace CardWords {

// Thrown when the resources of the computer are exploited:
// Low memory, too many filedescriptors etc.
class XLowResources : public Exception
{
public:
  // the libc errno that caused this exception
  int error_number;

  // a string describing the situation that caused this exception
  const string description;

  XLowResources (int en, const string & desc);
  XLowResources (const string & desc);

  void
  print(ostream &) const;
};


// Thrown when a bug in cardwords shows up:
class XInternal_Error : public Exception
{
public:
  // the libc errno that caused this exception
  int error_number;

  // a string describing the situation that caused this exception
  const string description;

  XInternal_Error (const string & desc);

  void
  print(ostream &) const;
};

  
// Thrown when a member of array/vector/map was requested with illegal
// argument:
class XOutOfRange : public Exception
{
public:
  // a string describing the situation that caused this exception
  const string description;

  XOutOfRange (const string & desc) 
    : description(desc) {};
  XOutOfRange (const XOutOfRange & o)
    : description(o.description) {};

  void
  print(ostream &) const;
};
  

// Thrown when a file does not exist or permissions deny the usage of it:
class XAccessingFile : public Exception
{
public:
  // the libc errno that caused this exception
  const int error_number;

  // a string describing the situation that caused this exception
  const string description;

  // the filename that caused this exception
  const string filename;

  XAccessingFile (int en, const string & desc, const string & fn);
  XAccessingFile (const string & desc, const string & fn);

  void
  print(ostream &) const;
};


// thrown when the input does not match the expected format:
class XBadInput : public Exception
{
public:
  const string description;
  const string expected;

  XBadInput (const string & desc, const string & exp);

  void
  print(ostream &) const;
};


// Thrown when a request for a member of a union is scheduled and that member
// is currently not existing and the type of the return value has no way to
// tell that the request was invalid (like a NULL pointer).
class XInvalidRequest : public Exception
{
public:
  // a string describing the situation that caused this exception
  const string description;

  XInvalidRequest (const string & desc)
    : description(desc){};

  void
  print(ostream &) const;
};

#define XBadNetworkMessage XBadInput
}
#endif

