1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
/*
* Copyright (C) 2000-2002 The Exult Team
*
* 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.
*/
#ifndef EXCEPTIONS_H
#define EXCEPTIONS_H
#ifndef ALPHA_LINUX_CXX
# include <cerrno>
#endif
#include <stdexcept>
#include <string>
/*
* Base class of all our exceptions, providing a storage for the error message
*/
class exult_exception : public std::exception {
std::string what_;
int errno_;
public:
exult_exception (const char *what_arg): what_ (what_arg), errno_(errno) { }
exult_exception (const std::string& what_arg): what_ (what_arg), errno_(errno) { }
const char *what() const throw () { return what_.c_str(); }
int get_errno(void) const { return errno_; }
virtual ~exult_exception () throw() {}
};
/*
* A quit exception can be thrown to quit the program
*/
class quit_exception : public exult_exception
{
int result_;
public:
quit_exception (int result = 0): exult_exception ("Quit"), result_(result) { }
int get_result(void) const { return result_; }
};
/*
* Classes which should not be replicatable throw an replication_exception
*/
class replication_exception : public exult_exception
{
public:
replication_exception (const char *what_arg): exult_exception (what_arg) { }
replication_exception (const std::string& what_arg): exult_exception (what_arg) { }
};
// Some handy macros which you can use to make a class non-replicable
#define UNREPLICATABLE_CLASS(NAME) NAME(const NAME &) { throw replication_exception( #NAME " cannot be replicated"); }; \
NAME &operator=(const NAME &) { throw replication_exception( #NAME " cannot be replicated"); return *this; }
#define UNREPLICATABLE_CLASS_I(NAME,INIT) NAME(const NAME &) : INIT { throw replication_exception( #NAME " cannot be replicated"); }; \
NAME &operator=(const NAME &) { throw replication_exception( #NAME " cannot be replicated"); return *this; }
/*
* File errors
*/
class file_exception : public exult_exception
{
public:
file_exception (const char *what_arg): exult_exception (what_arg) { }
file_exception (const std::string& what_arg): exult_exception (what_arg) { }
};
class file_open_exception : public file_exception {
static const std::string prefix_;
public:
file_open_exception (const std::string& file): file_exception("Error opening file "+file) { }
};
class file_write_exception : public file_exception {
static const std::string prefix_;
public:
file_write_exception(const std::string& file): file_exception("Error writing to file "+file) { }
};
class file_read_exception : public file_exception {
static const std::string prefix_;
public:
file_read_exception(const std::string& file): file_exception("Error reading from file "+file) { }
};
class wrong_file_type_exception : public file_exception {
public:
wrong_file_type_exception (const std::string& file, const std::string& type): file_exception("File "+file+" is not of type "+type) { }
};
/*
* Exception that gets fired when the user aborts something
*/
class UserBreakException
{
};
#endif
|