Merge master.
[libdcp.git] / src / exceptions.h
1 /*
2     Copyright (C) 2012-2014 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 #include <boost/filesystem.hpp>
24
25 /** @file  src/exceptions.h
26  *  @brief Exceptions thrown by libdcp.
27  */
28
29 namespace dcp
30 {
31
32 /** @class FileError
33  *  @brief An exception related to a file
34  */
35 class FileError : public std::exception
36 {
37 public:
38         FileError (std::string message, boost::filesystem::path filename, int number);
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         boost::filesystem::path filename () const {
48                 return _filename;
49         }
50
51         /** @return error number of the error */
52         int number () const {
53                 return _number;
54         }
55
56 private:
57         /** message part */
58         std::string _message;
59         /** filename of file that was involved */
60         boost::filesystem::path _filename;
61         int _number;
62 };
63
64 /** @class MXFFileError
65  *  @brief An exception related to an MXF file
66  */
67 class MXFFileError : public FileError
68 {
69 public:
70         MXFFileError (std::string message, boost::filesystem::path filename, int number)
71                 : FileError (message, filename, number)
72         {}
73 };
74         
75 /** @class MiscError
76  *  @brief A miscellaneous exception
77  */
78 class MiscError : public std::exception
79 {
80 public:
81         MiscError (std::string message) : _message (message) {}
82         ~MiscError () throw () {}
83
84         /** @return error message */
85         char const * what () const throw () {
86                 return _message.c_str ();
87         }
88
89 private:
90         /** error message */
91         std::string _message;
92 };
93
94 /** @class DCPReadError
95  *  @brief A DCP read exception
96  */
97 class DCPReadError : public std::exception
98 {
99 public:
100         DCPReadError (std::string message) : _message (message) {}
101         ~DCPReadError () throw () {}
102
103         /** @return error message */
104         char const * what () const throw () {
105                 return _message.c_str ();
106         }
107
108 private:
109         /** error message */
110         std::string _message;
111 };
112
113 /** @class XMLError
114  *  @brief An XML error
115  */
116 class XMLError : public std::exception
117 {
118 public:
119         XMLError (std::string message) : _message (message) {}
120         ~XMLError () throw () {}
121
122         /** @return error message */
123         char const * what () const throw () {
124                 return _message.c_str ();
125         }
126
127 private:
128         /** error message */
129         std::string _message;
130 };
131
132 /** @class UnresolvedRefError
133  *  @brief An exception caused by a reference (by UUID) to something which is not known
134  */
135 class UnresolvedRefError : public std::exception
136 {
137 public:
138         UnresolvedRefError (std::string id);
139         ~UnresolvedRefError () throw () {}
140
141         /** @return error message */
142         char const * what () const throw () {
143                 return _message.c_str ();
144         }
145
146 private:
147         std::string _message;
148 };
149         
150 }
151
152 #endif