Line data Source code
1 : #pragma once 2 : #ifndef ZIPIOS_ZIPIOSEXCEPTIONS_HPP 3 : #define ZIPIOS_ZIPIOSEXCEPTIONS_HPP 4 : 5 : /* 6 : Zipios -- a small C++ library that provides easy access to .zip files. 7 : 8 : Copyright (C) 2000-2007 Thomas Sondergaard 9 : Copyright (c) 2015-2022 Made to Order Software Corp. All Rights Reserved 10 : 11 : This library is free software; you can redistribute it and/or 12 : modify it under the terms of the GNU Lesser General Public 13 : License as published by the Free Software Foundation; either 14 : version 2.1 of the License, or (at your option) any later version. 15 : 16 : This library is distributed in the hope that it will be useful, 17 : but WITHOUT ANY WARRANTY; without even the implied warranty of 18 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 : Lesser General Public License for more details. 20 : 21 : You should have received a copy of the GNU Lesser General Public 22 : License along with this library; if not, write to the Free Software 23 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24 : */ 25 : 26 : /** \file 27 : * \brief Various exceptions used throughout the Zipios library, all 28 : * based on zipios::Exception. 29 : * 30 : * This header file defines a number of exceptions used throughout 31 : * the Zipios library. The declaration includes the implementation. 32 : * We really only offer a what() string along with the exceptions. 33 : * We may add some more exceptions to better separate the various 34 : * errors we generate. 35 : */ 36 : 37 : #include "zipios/zipios-config.hpp" 38 : 39 : #include <stdexcept> 40 : #include <string> 41 : 42 : 43 : namespace zipios 44 : { 45 : 46 : 47 : /** \brief Base exception of the zipios environment 48 : * 49 : * Unfortunately, all exceptions are marked as runtime_error. 50 : * 51 : * However, if we find a problem we will throw logic_error instead. 52 : * So if you get a logic_error, it is an error that we assume should 53 : * never occur. A runtime_error, on the other hand, is expected to 54 : * happen once in a while (i.e. cannot create a file, cannot read 55 : * a file, etc.) 56 : */ 57 : class Exception : public std::runtime_error 58 : { 59 : public: 60 91368 : Exception(std::string const & msg) : runtime_error(msg) {} 61 : }; 62 : 63 : 64 : 65 : /** \brief An IOException is used to signal an I/O error. 66 : * 67 : * If a file or directory cannot be opened, read, or written, this 68 : * exception is raised. 69 : */ 70 : class IOException : public Exception 71 : { 72 : public: 73 62334 : IOException(std::string const & msg) : Exception(msg) {} 74 : }; 75 : 76 : 77 : /** \brief An InvalidException is used when invalid data is provided. 78 : * 79 : * When calling a function, if one of the input parameters is invalid 80 : * then this exception is raised. 81 : */ 82 : class InvalidException : public Exception 83 : { 84 : public: 85 22686 : InvalidException(std::string const & msg) : Exception(msg) {} 86 : }; 87 : 88 : 89 : /** \brief FileCollectionException is used to signal a FileCollection problem. 90 : * 91 : * A process dealing with a collection of files will use this exception 92 : * if a problem arise while dealing with that collection. 93 : */ 94 : class FileCollectionException : public Exception 95 : { 96 : public: 97 73 : FileCollectionException(std::string const & msg) : Exception(msg) {} 98 : }; 99 : 100 : 101 : /** \brief Exception used when it is not possible to move forward. 102 : * 103 : * An object member function may throw this exception when the 104 : * operation it normally performs is inappropriate or impossible to 105 : * perform because of the current state of the object. 106 : */ 107 : class InvalidStateException : public Exception 108 : { 109 : public: 110 6275 : InvalidStateException(std::string const & msg) : Exception(msg) {} 111 : }; 112 : 113 : 114 : } // zipios namespace 115 : 116 : // Local Variables: 117 : // mode: cpp 118 : // indent-tabs-mode: nil 119 : // c-basic-offset: 4 120 : // tab-width: 4 121 : // End: 122 : 123 : // vim: ts=4 sw=4 et 124 : #endif