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 dgui.core.exception;
10 
11 import std..string: format;
12 import std.windows.syserror;
13 import dgui.core.winapi: GetLastError;
14 
15 mixin template exceptionBody()
16 {
17 	public this(string msg)
18 	{
19 		super(msg);
20 	}
21 }
22 
23 final class DGuiException: Exception
24 {
25 	mixin exceptionBody;
26 }
27 
28 final class Win32Exception: Exception
29 {
30 	mixin exceptionBody;
31 }
32 
33 final class RegistryException: Exception
34 {
35 	mixin exceptionBody;
36 }
37 
38 final class GDIException: Exception
39 {
40 	mixin exceptionBody;
41 }
42 
43 final class WindowsNotSupportedException: Exception
44 {
45 	mixin exceptionBody;
46 }
47 
48 void throwException(T1, T2...)(string fmt, T2 args)
49 {
50 	static if(is(T1: Win32Exception))
51 	{
52 		throw new T1(format(fmt ~ "\nWindows Message: '%s'", args, sysErrorString(GetLastError())));
53 	}
54 	else
55 	{
56 		throw new T1(format(fmt, args));
57 	}
58 }