Tweaks to dcpinfo.
[libdcp.git] / src / exceptions.h
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef LIBDCP_EXCEPTIONS_H
21 #define LIBDCP_EXCEPTIONS_H
22
23 /** @file  src/exceptions.h
24  *  @brief Exceptions thrown by libdcp.
25  */
26
27 namespace libdcp
28 {
29
30 /** @brief An exception related to a file */
31 class FileError : public std::exception
32 {
33 public:
34         FileError (std::string const & message, std::string const & filename)
35                 : _message (message)
36                 , _filename (filename)
37         {}
38                             
39         ~FileError () throw () {}
40
41         /** @return error message */
42         char const * what () const throw () {
43                 return _message.c_str ();
44         }
45         
46         /** @return filename of file that was involved */
47         std::string filename () const {
48                 return _filename;
49         }
50
51 private:
52         /** error message */
53         std::string _message;
54         /** filename of file that was involved */
55         std::string _filename;
56 };
57
58 class MXFFileError : public FileError
59 {
60 public:
61         MXFFileError (std::string const & message, std::string const & filename)
62                 : FileError (message, filename)
63         {}
64 };
65         
66 /** @brief A miscellaneous exception */
67 class MiscError : public std::exception
68 {
69 public:
70         MiscError (std::string const & message) : _message (message) {}
71         ~MiscError () throw () {}
72
73         /** @return error message */
74         char const * what () const throw () {
75                 return _message.c_str ();
76         }
77
78 private:
79         /** error message */
80         std::string _message;
81 };
82
83 /** @brief A DCP read exception */
84 class DCPReadError : public std::exception
85 {
86 public:
87         DCPReadError (std::string const & message) : _message (message) {}
88         ~DCPReadError () throw () {}
89
90         /** @return error message */
91         char const * what () const throw () {
92                 return _message.c_str ();
93         }
94
95 private:
96         /** error message */
97         std::string _message;
98 };
99
100 /** @brief An XML error */
101 class XMLError : public std::exception
102 {
103 public:
104         XMLError (std::string const & message) : _message (message) {}
105         ~XMLError () throw () {}
106
107         /** @return error message */
108         char const * what () const throw () {
109                 return _message.c_str ();
110         }
111
112 private:
113         /** error message */
114         std::string _message;
115 };
116         
117 }
118
119 #endif