4
* A Low Level GPU Graphics and Utilities API
6
* Copyright (C) 2012 Intel Corporation.
8
* Permission is hereby granted, free of charge, to any person
9
* obtaining a copy of this software and associated documentation
10
* files (the "Software"), to deal in the Software without
11
* restriction, including without limitation the rights to use, copy,
12
* modify, merge, publish, distribute, sublicense, and/or sell copies
13
* of the Software, and to permit persons to whom the Software is
14
* furnished to do so, subject to the following conditions:
16
* The above copyright notice and this permission notice shall be
17
* included in all copies or substantial portions of the Software.
19
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
23
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
30
#error "Only <cogl/cogl.h> can be included directly."
33
#ifndef __COGL_ERROR_H__
34
#define __COGL_ERROR_H__
36
#include "cogl-types.h"
42
* @short_description: A way for Cogl to throw exceptions
44
* As a general rule Cogl shields non-recoverable errors from
45
* developers, such as most heap allocation failures (unless for
46
* exceptionally large resources which we might reasonably expect to
47
* fail) and this reduces the burden on developers.
49
* There are some Cogl apis though that can fail for exceptional
50
* reasons that can also potentially be recovered from at runtime
51
* and for these apis we use a standard convention for reporting
52
* runtime recoverable errors.
54
* As an example if we look at the cogl_context_new() api which
55
* takes an error argument:
58
* cogl_context_new (CoglDisplay *display, CoglError **error);
61
* A caller interested in catching any runtime error when creating a
62
* new #CoglContext would pass the address of a #CoglError pointer
63
* that has first been initialized to %NULL as follows:
66
* CoglError *error = NULL;
67
* CoglContext *context;
69
* context = cogl_context_new (NULL, &error);
72
* The return status should usually be enough to determine if there
73
* was an error set (in this example we can check if context == %NULL)
74
* but if it's not possible to tell from the function's return status
75
* you can instead look directly at the error pointer which you
76
* initialized to %NULL. In this example we now check the error,
77
* report any error to the user, free the error and then simply
78
* abort without attempting to recover.
81
* if (context == NULL)
83
* fprintf (stderr, "Failed to create a Cogl context: %s\n",
85
* cogl_error_free (error);
90
* All Cogl APIs that accept an error argument can also be passed a
91
* %NULL pointer. In this case if an exceptional error condition is hit
92
* then Cogl will simply log the error message and abort the
93
* application. This can be compared to language execeptions where the
94
* developer has not attempted to catch the exception. This means the
95
* above example is essentially redundant because it's what Cogl would
96
* have done automatically and so, similarly, if your application has
97
* no way to recover from a particular error you might just as well
98
* pass a %NULL #CoglError pointer to save a bit of typing.
100
* <note>If you are used to using the GLib API you will probably
101
* recognize that #CoglError is just like a #GError. In fact if Cogl
102
* has been built with --enable-glib then it is safe to cast a
103
* #CoglError to a #GError.</note>
105
* <note>An important detail to be aware of if you are used to using
106
* GLib's GError API is that Cogl deviates from the GLib GError
107
* conventions in one noteable way which is that a %NULL error pointer
108
* does not mean you want to ignore the details of an error, it means
109
* you are not trying to catch any exceptional errors the function might
110
* throw which will result in the program aborting with a log message
111
* if an error is thrown.</note>
114
#define CoglError GError
118
* @error: A #CoglError thrown by the Cogl api
120
* Frees a #CoglError and associated resources.
123
cogl_error_free (CoglError *error);
127
* @error: A #CoglError thrown by the Cogl api
129
* Makes a copy of @error which can later be freed using
132
* Return value: A newly allocated #CoglError initialized to match the
133
* contents of @error.
136
cogl_error_copy (CoglError *error);
139
* cogl_error_matches:
140
* @error: A #CoglError thrown by the Cogl api or %NULL
141
* @domain: The error domain
142
* @code: The error code
144
* Returns %TRUE if error matches @domain and @code, %FALSE otherwise.
145
* In particular, when error is %NULL, FALSE will be returned.
147
* Return value: whether the @error corresponds to the given @domain
151
cogl_error_matches (CoglError *error,
157
* @COGL_ERROR: A #CoglError thrown by the Cogl api or %NULL
159
* Simply casts a #CoglError to a #CoglError
161
* If Cogl is built with GLib support then it can safely be assumed
162
* that a CoglError is a GError and can be used directly with the
165
#define COGL_GLIB_ERROR(COGL_ERROR) ((CoglError *)COGL_ERROR)
169
#endif /* __COGL_ERROR_H__ */