00001 /* 00002 * Copyright (C) 2000-2002 The Exult Team 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #ifndef EXCEPTIONS_H 00020 #define EXCEPTIONS_H 00021 00022 #ifndef ALPHA_LINUX_CXX 00023 # include <cerrno> 00024 #endif 00025 #include <stdexcept> 00026 #include <string> 00027 00028 /* 00029 * Base class of all our exceptions, providing a storage for the error message 00030 */ 00031 00032 class exult_exception : public std::exception { 00033 std::string what_; 00034 int errno_; 00035 public: 00036 exult_exception (const char *what_arg): what_ (what_arg), errno_(errno) { } 00037 exult_exception (const std::string& what_arg): what_ (what_arg), errno_(errno) { } 00038 const char *what() const throw () { return what_.c_str(); } 00039 int get_errno(void) const { return errno_; } 00040 virtual ~exult_exception () throw() {} 00041 }; 00042 00043 00044 /* 00045 * A quit exception can be thrown to quit the program 00046 */ 00047 00048 class quit_exception : public exult_exception 00049 { 00050 int result_; 00051 public: 00052 quit_exception (int result = 0): exult_exception ("Quit"), result_(result) { } 00053 int get_result(void) const { return result_; } 00054 }; 00055 00056 /* 00057 * Classes which should not be replicatable throw an replication_exception 00058 */ 00059 00060 class replication_exception : public exult_exception 00061 { 00062 public: 00063 replication_exception (const char *what_arg): exult_exception (what_arg) { } 00064 replication_exception (const std::string& what_arg): exult_exception (what_arg) { } 00065 }; 00066 00067 // Some handy macros which you can use to make a class non-replicable 00068 #define UNREPLICATABLE_CLASS(NAME) NAME(const NAME &) { throw replication_exception( #NAME " cannot be replicated"); }; \ 00069 NAME &operator=(const NAME &) { throw replication_exception( #NAME " cannot be replicated"); return *this; } 00070 00071 #define UNREPLICATABLE_CLASS_I(NAME,INIT) NAME(const NAME &) : INIT { throw replication_exception( #NAME " cannot be replicated"); }; \ 00072 NAME &operator=(const NAME &) { throw replication_exception( #NAME " cannot be replicated"); return *this; } 00073 00074 00075 00076 /* 00077 * File errors 00078 */ 00079 00080 class file_exception : public exult_exception 00081 { 00082 public: 00083 file_exception (const char *what_arg): exult_exception (what_arg) { } 00084 file_exception (const std::string& what_arg): exult_exception (what_arg) { } 00085 }; 00086 00087 class file_open_exception : public file_exception { 00088 static const std::string prefix_; 00089 public: 00090 file_open_exception (const std::string& file): file_exception("Error opening file "+file) { } 00091 }; 00092 00093 class file_write_exception : public file_exception { 00094 static const std::string prefix_; 00095 public: 00096 file_write_exception(const std::string& file): file_exception("Error writing to file "+file) { } 00097 }; 00098 00099 class file_read_exception : public file_exception { 00100 static const std::string prefix_; 00101 public: 00102 file_read_exception(const std::string& file): file_exception("Error reading from file "+file) { } 00103 }; 00104 00105 class wrong_file_type_exception : public file_exception { 00106 public: 00107 wrong_file_type_exception (const std::string& file, const std::string& type): file_exception("File "+file+" is not of type "+type) { } 00108 }; 00109 00110 00111 /* 00112 * Exception that gets fired when the user aborts something 00113 */ 00114 class UserBreakException 00115 { 00116 }; 00117 00118 #endif