root/trunk/cairo/cairooo/exceptions.d

Revision 179, 4.2 kB (checked in by DRK, 5 years ago)

* Updated everything in cairo so that it compiles in the latest version of DMD. Also re-ran all the snippets, demos and tutorials, and checked that they worked.

Line 
1 /**
2     Defines various exceptions that can be thrown by the binding.
3     
4 Authors: Daniel Keep
5 Copyright: 2006, Daniel Keep
6 License: BSD v2 (http://opensource.org/licenses/bsd-license.php).
7 **/
8 /**
9     Copyright © 2006 Daniel Keep
10     All rights reserved.
11     
12     Redistribution and use in source and binary forms, with or without
13     modification, are permitted provided that the following conditions are
14     met:
15     
16     * Redistributions of source code must retain the above copyright
17       notice, this list of conditions and the following disclaimer.
18       
19     * Redistributions in binary form must reproduce the above copyright
20       notice, this list of conditions and the following disclaimer in the
21       documentation and/or other materials provided with the distribution.
22     
23     * Neither the name of this software, nor the names of its contributors
24       may be used to endorse or promote products derived from this software
25       without specific prior written permission.
26     
27     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30     PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
31     CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32     EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33     PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34     PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35     LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36     NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 **/
39 module cairooo.exceptions;
40
41 private
42 {
43     import std.outofmemory;
44     import cairo.cairo;
45 }
46
47 void
48 checkStatus(cairo_status_t status)
49 {
50     switch(status)
51     {
52         case cairo_status_t.CAIRO_STATUS_SUCCESS:
53             break;
54
55         case cairo_status_t.CAIRO_STATUS_NO_MEMORY:
56             throw new CairoNoMemoryException;
57
58         case cairo_status_t.CAIRO_STATUS_READ_ERROR:
59             throw new CairoReadException;
60            
61         case cairo_status_t.CAIRO_STATUS_WRITE_ERROR:
62             throw new CairoWriteException;
63            
64         case cairo_status_t.CAIRO_STATUS_INVALID_RESTORE:
65         case cairo_status_t.CAIRO_STATUS_INVALID_POP_GROUP: // Damn you N'sync!
66         case cairo_status_t.CAIRO_STATUS_NO_CURRENT_POINT:
67         case cairo_status_t.CAIRO_STATUS_INVALID_MATRIX:
68         case cairo_status_t.CAIRO_STATUS_INVALID_STATUS:
69         case cairo_status_t.CAIRO_STATUS_INVALID_STRING:
70         case cairo_status_t.CAIRO_STATUS_SURFACE_FINISHED:
71         case cairo_status_t.CAIRO_STATUS_INVALID_CONTENT:
72         case cairo_status_t.CAIRO_STATUS_INVALID_FORMAT:
73         case cairo_status_t.CAIRO_STATUS_INVALID_VISUAL:
74         case cairo_status_t.CAIRO_STATUS_FILE_NOT_FOUND:
75         case cairo_status_t.CAIRO_STATUS_INVALID_DASH:
76             throw new CairoFatalError;
77
78         case cairo_status_t.CAIRO_STATUS_NULL_POINTER:
79         case cairo_status_t.CAIRO_STATUS_INVALID_PATH_DATA:
80         case cairo_status_t.CAIRO_STATUS_SURFACE_TYPE_MISMATCH:
81         case cairo_status_t.CAIRO_STATUS_PATTERN_TYPE_MISMATCH:
82             throw new CairoBindingError;
83            
84         default:
85             throw new CairoUnknownException;
86     }
87 }
88
89 package
90 {
91     template Ex(alias base)
92     {
93         class Ex : base
94         {
95             this(char[] msg) { super(msg); }
96         }
97     }
98    
99     template Ex(alias base, char[] message)
100     {
101         class Ex : base
102         {
103             this() { super(message); }
104             this(char[] msg) { super(message ~ ": " ~ msg); }
105         }
106     }
107 }
108
109 alias Ex!(Exception, "cairo read error")    CairoReadException;
110 alias Ex!(Exception, "cairo write error")   CairoWriteException;
111 alias Ex!(Exception, "Unknown cairo error") CairoUnknownException;
112 alias Ex!(Error, "Fatal cairo error")       CairoFatalError;
113 alias Ex!(Error, "cairo binding error")     CairoBindingError;
114
115 class CairoNoMemoryException : OutOfMemoryException {}
Note: See TracBrowser for help on using the browser.