|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2003/XInclude" type="topic" id="gerror" xml:lang="de">
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<link type="guide" xref="index#specific-how-tos"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Philip Withnall</name>
|
|
Packit |
1470ea |
<email its:translate="no">philip.withnall@collabora.co.uk</email>
|
|
Packit |
1470ea |
<years>2015</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<include xmlns="http://www.w3.org/2001/XInclude" href="cc-by-sa-3-0.xml"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>Umgang mit und Melden von Laufzeitfehlern</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Mario Blättermann</mal:name>
|
|
Packit |
1470ea |
<mal:email>mario.blaettermann@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2016</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Christian Kirbach</mal:name>
|
|
Packit |
1470ea |
<mal:email>christian.kirbach@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2016</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>GError</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="gerror-usage">
|
|
Packit |
1470ea |
<title>Verwendung von GError</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<link href="https://developer.gnome.org/glib/stable/glib-Error-Reporting.html">GError </link>
|
|
Packit |
1470ea |
is the standard error reporting mechanism for GLib-using code, and can be
|
|
Packit |
1470ea |
thought of as a C implementation of an
|
|
Packit |
1470ea |
<link href="http://en.wikipedia.org/wiki/Exception_handling">exception</link>.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Any kind of runtime failure (anything which is not a
|
|
Packit |
1470ea |
<link xref="preconditions">programmer error</link>) must be handled by
|
|
Packit |
1470ea |
including a GError** parameter in the function, and setting a
|
|
Packit |
1470ea |
useful and relevant GError describing the failure, before returning from
|
|
Packit |
1470ea |
the function. Programmer errors must not be handled using GError: use
|
|
Packit |
1470ea |
assertions, pre-conditions or post-conditions instead.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
GError should be used in preference to a simple return code, as it can
|
|
Packit |
1470ea |
convey more information, and is also supported by all GLib tools. For
|
|
Packit |
1470ea |
example, <link xref="introspection">introspecting an API</link> will
|
|
Packit |
1470ea |
automatically detect all GError parameters so that they can be converted
|
|
Packit |
1470ea |
to exceptions in other languages.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Printing warnings to the console must not be done in library code: use a
|
|
Packit |
1470ea |
GError, and the calling code can propagate it further upwards, decide to
|
|
Packit |
1470ea |
handle it, or decide to print it to the console. Ideally, the only code
|
|
Packit |
1470ea |
which prints to the console will be top-level application code, and not
|
|
Packit |
1470ea |
library code.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Any function call which can take a GError** , should
|
|
Packit |
1470ea |
take such a parameter, and the returned GError should be handled
|
|
Packit |
1470ea |
appropriately. There are very few situations where ignoring a potential
|
|
Packit |
1470ea |
error by passing NULL to a GError** parameter is
|
|
Packit |
1470ea |
acceptable.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
The GLib API documentation contains a
|
|
Packit |
1470ea |
<link href="https://developer.gnome.org/glib/stable/glib-Error-Reporting.html#glib-Error-Reporting.description">full
|
|
Packit |
1470ea |
tutorial for using GError</link>.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
</page>
|