1 /** DGui project file.
2 
3 Copyright: Trogu Antonio Davide 2011-2013
4 
5 License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
6 
7 Authors: Trogu Antonio Davide
8 */
9 module dguihub.core.exception;
10 
11 import std..string : format;
12 import std.windows.syserror;
13 import dguihub.core.winapi : GetLastError;
14 
15 mixin template exceptionBody() {
16    public this(string msg) {
17       super(msg);
18    }
19 }
20 
21 final class DGuiException : Exception {
22    mixin exceptionBody;
23 }
24 
25 final class Win32Exception : Exception {
26    mixin exceptionBody;
27 }
28 
29 final class RegistryException : Exception {
30    mixin exceptionBody;
31 }
32 
33 final class GDIException : Exception {
34    mixin exceptionBody;
35 }
36 
37 final class WindowsNotSupportedException : Exception {
38    mixin exceptionBody;
39 }
40 
41 void throwException(T1, T2...)(string fmt, T2 args) {
42    static if (is(T1 : Win32Exception)) {
43       throw new T1(format(fmt ~ "\nWindows Message: '%s'", args, sysErrorString(GetLastError())));
44    } else {
45       throw new T1(format(fmt, args));
46    }
47 }