Add reporting of DCP type.
[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::runtime_error
36 {
37 public:
38         FileError (std::string message, boost::filesystem::path filename, int number);
39         ~FileError () throw () {}
40
41         /** @return filename of file that was involved */
42         boost::filesystem::path filename () const {
43                 return _filename;
44         }
45
46         /** @return error number of the error */
47         int number () const {
48                 return _number;
49         }
50
51 private:
52         /** filename of file that was involved */
53         boost::filesystem::path _filename;
54         int _number;
55 };
56
57 /** @class MXFFileError
58  *  @brief An exception related to an MXF file
59  */
60 class MXFFileError : public FileError
61 {
62 public:
63         MXFFileError (std::string message, boost::filesystem::path filename, int number)
64                 : FileError (message, filename, number)
65         {}
66 };
67
68 /** @class MiscError
69  *  @brief A miscellaneous exception
70  */
71 class MiscError : public std::runtime_error
72 {
73 public:
74         MiscError (std::string message)
75                 : std::runtime_error (message)
76         {}
77 };
78
79 /** @class DCPReadError
80  *  @brief A DCP read exception
81  */
82 class DCPReadError : public std::runtime_error
83 {
84 public:
85         DCPReadError (std::string message)
86                 : std::runtime_error (message)
87         {}
88 };
89
90 /** @class MissingAssetError
91  *  @brief An error of a missing asset.
92  */
93 class MissingAssetError : public DCPReadError
94 {
95 public:
96         enum AssetType {
97                 MAIN_PICTURE,  //< main picture is missing
98                 MAIN_SOUND,    //< main sound is missing
99                 MAIN_SUBTITLE, //< main subtitle is missing
100                 UNKNOWN        //< something is missing but we don't know what
101         };
102
103         MissingAssetError (boost::filesystem::path, AssetType = UNKNOWN);
104         ~MissingAssetError () throw () {}
105 };
106
107 /** @class XMLError
108  *  @brief An XML error
109  */
110 class XMLError : public std::runtime_error
111 {
112 public:
113         XMLError (std::string message)
114                 : std::runtime_error (message)
115         {}
116 };
117
118 /** @class UnresolvedRefError
119  *  @brief An exception caused by a reference (by UUID) to something which is not known
120  */
121 class UnresolvedRefError : public std::runtime_error
122 {
123 public:
124         UnresolvedRefError (std::string id);
125 };
126
127 /** @class TimeFormatError
128  *  @brief A an error with a string passed to LocalTime.
129  */
130 class TimeFormatError : public std::runtime_error
131 {
132 public:
133         TimeFormatError (std::string bad_time);
134 };
135
136 /** @class NotEncryptedError
137  *  @brief An error raised when creating a DecryptedKDM object for assets that are not
138  *  encrypted.
139  */
140 class NotEncryptedError : public std::runtime_error
141 {
142 public:
143         NotEncryptedError (std::string const & what);
144         ~NotEncryptedError () throw () {}
145 };
146
147 /** @class ProgrammingError
148  *  @brief An exception thrown when a DCP_ASSERT fails; something that should not happen.
149  */
150 class ProgrammingError : public std::runtime_error
151 {
152 public:
153         ProgrammingError (std::string file, int line);
154 };
155
156 class MismatchedStandardError : public DCPReadError
157 {
158 public:
159         MismatchedStandardError ();
160 };
161
162 }
163
164 #endif