00001 /* 00002 * Exception.h : part of the Mace toolkit for building distributed systems 00003 * 00004 * Copyright (c) 2007, Charles Killian, Dejan Kostic, Ryan Braud, James W. Anderson, John Fisher-Ogden, Calvin Hubble, Duy Nguyen, Justin Burke, David Oppenheimer, Amin Vahdat, Adolfo Rodriguez, Sooraj Bhat 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are met: 00009 * 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in 00014 * the documentation and/or other materials provided with the 00015 * distribution. 00016 * * Neither the names of Duke University nor The University of 00017 * California, San Diego, nor the names of the authors or contributors 00018 * may be used to endorse or promote products derived from 00019 * this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00022 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 00025 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00026 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00027 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00028 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00029 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00030 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 * 00032 * ----END-OF-LEGAL-STUFF---- */ 00033 #include <string> 00034 #include <map> 00035 #include "Printable.h" 00036 00037 #ifndef EXCEPTION_H 00038 #define EXCEPTION_H 00039 00047 00048 class Exception : public std::exception, public mace::ToStringPrintable { 00049 public: 00050 Exception() { } 00051 virtual ~Exception() throw() { } 00052 Exception(const std::string& m) : message(m) { } 00053 virtual const char* what() const throw() { return message.c_str(); } 00054 virtual std::string toString() const { return message; } 00055 virtual void rethrow() const { throw *this; } 00056 00057 protected: 00058 std::string message; 00059 00060 }; // Exception 00061 00063 class IOException : public Exception { 00064 public: 00065 IOException(const std::string& m) : Exception(m) { } 00066 virtual void rethrow() const { throw *this; } 00067 }; // IOException 00068 00070 class FileException : public IOException { 00071 public: 00072 FileException(const std::string& m) : IOException(m) { } 00073 virtual void rethrow() const { throw *this; } 00074 }; // FileException 00075 00077 class BadFileTypeException : public FileException { 00078 public: 00079 BadFileTypeException(const std::string& m) : FileException(m) { } 00080 virtual void rethrow() const { throw *this; } 00081 }; // BadFileTypeException 00082 00084 class FileNotFoundException : public FileException { 00085 public: 00086 FileNotFoundException(const std::string& m) : FileException(m) { } 00087 virtual void rethrow() const { throw *this; } 00088 }; // FileNotFoundException 00089 00091 class InvalidPathException : public FileException { 00092 public: 00093 InvalidPathException(const std::string& m) : FileException(m) { } 00094 virtual void rethrow() const { throw *this; } 00095 }; // InvalidPathException 00096 00098 class PermissionAccessException : public FileException { 00099 public: 00100 PermissionAccessException(const std::string& m) : FileException(m) { } 00101 virtual void rethrow() const { throw *this; } 00102 }; // PermissionAccessException 00103 00105 class LinkLoopException : public FileException { 00106 public: 00107 LinkLoopException(const std::string& m) : FileException(m) { } 00108 virtual void rethrow() const { throw *this; } 00109 }; // LinkLoopException 00110 00112 class ReadException : public IOException { 00113 public: 00114 ReadException(const std::string& m) : IOException(m) { } 00115 virtual void rethrow() const { throw *this; } 00116 }; // ReadException 00117 00119 class WriteException : public IOException { 00120 public: 00121 WriteException(const std::string& m) : IOException(m) { } 00122 virtual void rethrow() const { throw *this; } 00123 }; // WriteException 00124 00126 class PipeClosedException : public WriteException { 00127 public: 00128 PipeClosedException(const std::string& m) : WriteException(m) { } 00129 virtual void rethrow() const { throw *this; } 00130 }; // PipeClosedException 00131 00133 class IncomparableException : public Exception { 00134 public: 00135 IncomparableException(const std::string& m) : Exception(m) { } 00136 virtual void rethrow() const { throw *this; } 00137 }; // IncomparableException 00138 00140 class AddressException : public Exception { 00141 public: 00142 AddressException(const std::string& m) : Exception(m) { } 00143 virtual void rethrow() const { throw *this; } 00144 }; // AddressException 00145 00147 class UnreachablePrivateAddressException : public AddressException { 00148 public: 00149 UnreachablePrivateAddressException(const std::string& m) : AddressException(m) { } 00150 virtual void rethrow() const { throw *this; } 00151 }; // UnreachablePrivateAddressException 00152 00153 #endif // EXCEPTION_H 00154