• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

D bindings to the GraphicsMagick library.


Commit MetaInfo

Revisión154f374257c8d9b73268853afff86e734a357f15 (tree)
Tiempo2023-07-23 13:07:43
AutorMio <stigma@disr...>
CommiterMio

Log Message

[magickd] Update Exception classes

Future proofing by separating the API exceptions (from GraphicsMagick)
vs any errors that MagickD might throw itself.

Cambiar Resumen

Diferencia incremental

--- a/source/magickd/exception.d
+++ b/source/magickd/exception.d
@@ -23,36 +23,115 @@
2323 */
2424 module magickd.exception;
2525
26-import core.stdc.string : strlen;
26+import std.string : fromStringz;
2727
28-import std.algorithm.mutation : copy;
28+import graphicsmagick_c.magick.error : ExceptionInfo;
2929
30-import graphicsmagick_c.magick.error;
30+///
31+/// Base exception class encompassing all MagickD exceptions.
32+///
33+/// Author: Mio
34+/// See_Also: MagickAPIException
35+///
36+class MagickException : Exception
37+{
38+package(magickd):
3139
32-class MagickException : Exception {
33- public ExceptionType severity;
34- public string description;
40+ ///
41+ /// Construct an exception
42+ ///
43+ public this(string msg)
44+ {
45+ super(msg);
46+ }
47+}
48+
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
58+{
59+package(magickd):
60+
61+ ///
62+ /// Descibes the exception that has occurred.
63+ ///
64+ private string m_description;
65+
66+ ///
67+ /// Reason for the exception being thrown.
68+ ///
69+ private string m_reason;
3570
36- this(ExceptionInfo ei) {
37- this.severity = ei.severity;
71+ ///
72+ /// Severity of the exception
73+ ///
74+ private int m_severity;
3875
39- string msg;
40- string desc;
76+ ///
77+ /// Construct an API exception
78+ ///
79+ /// Params:
80+ /// exception = The ExceptionInfo structure from GraphicsMagick.
81+ ///
82+ this(ref ExceptionInfo exception)
83+ {
84+ m_severity = exception.severity;
85+ m_reason = fromStringz(exception.reason).dup;
86+ m_description = fromStringz(exception.description).dup;
87+ super(m_reason);
88+ }
4189
42- size_t reasonLen = strlen(ei.reason);
43- size_t descLen = strlen(ei.description);
90+ ///
91+ /// Descibes the exception that has occurred.
92+ ///
93+ @property public string description() const
94+ {
95+ return m_description;
96+ }
4497
45- msg.reserve(reasonLen);
46- msg.length = reasonLen;
98+ ///
99+ /// Reason for the exception being thrown.
100+ ///
101+ @property public string reason() const
102+ {
103+ return m_reason;
104+ }
47105
48- desc.reserve(descLen);
49- desc.length = descLen;
106+ ///
107+ /// Severity of the exception
108+ ///
109+ @property public int severity() const
110+ {
111+ return m_severity;
112+ }
50113
51- copy(ei.reason[0..reasonLen], cast(char[])msg);
52- copy(ei.description[0..descLen], cast(char[])desc);
114+ ///
115+ /// Descibes the exception that has occurred.
116+ ///
117+ public string getDescription() const
118+ {
119+ return m_description;
120+ }
53121
54- this.description = desc;
122+ ///
123+ /// Reason for the exception being thrown.
124+ ///
125+ public string getReason() const
126+ {
127+ return m_reason;
128+ }
55129
56- super(msg);
57- }
130+ ///
131+ /// Severity of the exception
132+ ///
133+ public int getSeverity() const
134+ {
135+ return m_severity;
136+ }
58137 }
--- a/source/magickd/image.d
+++ b/source/magickd/image.d
@@ -62,7 +62,7 @@ class Image {
6262 GetExceptionInfo(&exception);
6363 handle = ReadImage(info_.handle, &exception);
6464 if (UndefinedException != exception.severity) {
65- throw new MagickException(exception);
65+ throw new MagickAPIException(exception);
6666 }
6767 }
6868
@@ -71,7 +71,7 @@ class Image {
7171 GetExceptionInfo(&exception);
7272 handle = PingImage(info_.handle, &exception);
7373 if (UndefinedException != exception.severity) {
74- throw new MagickException(exception);
74+ throw new MagickAPIException(exception);
7575 }
7676 }
7777
@@ -177,7 +177,7 @@ class Image {
177177 cImage* repl = AddNoiseImage(orig, noiseType, &exception);
178178
179179 if (UndefinedException != exception.severity) {
180- throw new MagickException(exception);
180+ throw new MagickAPIException(exception);
181181 }
182182 this.handle = repl;
183183 DestroyImage(orig);
@@ -201,7 +201,7 @@ class Image {
201201 cImage* repl = BlurImage(orig, radius, stigma, &exception);
202202
203203 if (UndefinedException != exception.severity) {
204- throw new MagickException(exception);
204+ throw new MagickAPIException(exception);
205205 }
206206 this.handle = repl;
207207 DestroyImage(orig);