[magickd] Update Exception classes
[magickd.git] / source / magickd / exception.d
blobcf563d914d953a970caa62925b565b782414f189
1 /*
2 File: magickd/exception.d
3 Contains: Exception handling within the magickd package.
4 Copyright: (C) 2023 Mio
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
24 module magickd.exception;
26 import std.string : fromStringz;
28 import graphicsmagick_c.magick.error : ExceptionInfo;
30 ///
31 /// Base exception class encompassing all MagickD exceptions.
32 ///
33 /// Author: Mio
34 /// See_Also: MagickAPIException
35 ///
36 class MagickException : Exception
38 package(magickd):
40 ///
41 /// Construct an exception
42 ///
43 public this(string msg)
45 super(msg);
49 ///
50 /// Encapsulates a GraphicsMagick ExceptionInfo structure.
51 ///
52 /// Used whenever a MagickWand/PixelWand/DrawingWand throw an
53 /// exception in the C API.
54 ///
55 /// Author: Mio
56 ///
57 class MagickAPIException : MagickException
59 package(magickd):
61 ///
62 /// Descibes the exception that has occurred.
63 ///
64 private string m_description;
66 ///
67 /// Reason for the exception being thrown.
68 ///
69 private string m_reason;
71 ///
72 /// Severity of the exception
73 ///
74 private int m_severity;
76 ///
77 /// Construct an API exception
78 ///
79 /// Params:
80 /// exception = The ExceptionInfo structure from GraphicsMagick.
81 ///
82 this(ref ExceptionInfo exception)
84 m_severity = exception.severity;
85 m_reason = fromStringz(exception.reason).dup;
86 m_description = fromStringz(exception.description).dup;
87 super(m_reason);
90 ///
91 /// Descibes the exception that has occurred.
92 ///
93 @property public string description() const
95 return m_description;
98 ///
99 /// Reason for the exception being thrown.
101 @property public string reason() const
103 return m_reason;
107 /// Severity of the exception
109 @property public int severity() const
111 return m_severity;
115 /// Descibes the exception that has occurred.
117 public string getDescription() const
119 return m_description;
123 /// Reason for the exception being thrown.
125 public string getReason() const
127 return m_reason;
131 /// Severity of the exception
133 public int getSeverity() const
135 return m_severity;