1Glib::Error(3)        User Contributed Perl Documentation       Glib::Error(3)
2
3
4

NAME

6       Glib::Error -  Exception Objects based on GError
7

SYNOPSIS

9         eval {
10            my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file ($filename);
11            $image->set_from_pixbuf ($pixbuf);
12         };
13         if ($@) {
14            print "$@\n";
15            if (Glib::Error::matches ($@, 'Gtk2::Gdk::Pixbuf::Error',
16                                          'unknown-format')) {
17               change_format_and_try_again ();
18            } elsif (Glib::Error::matches ($@, 'Glib::File::Error', 'noent')) {
19               change_source_dir_and_try_again ();
20            } else {
21               # don't know how to handle this
22               die $@;
23            }
24         }
25

DESCRIPTION

27       Gtk2-Perl translates GLib's GError runtime errors into Perl exceptions,
28       by creating exception objects based on Glib::Error.  Glib::Error
29       overloads the stringification operator, so a Glib::Error object will
30       act like a string if used with print() or warn(), so most code using $@
31       will not even know the difference.
32
33       The point of having exception objects, however, is that the error
34       messages in GErrors are often localized with NLS translation.  Thus,
35       it's not good for your code to attempt to handle errors by string
36       matching on the the error message.  Glib::Error provides a way to get
37       to the deterministic error code.
38
39       You will typically deal with objects that inherit from Glib::Error,
40       such as Glib::Convert::Error, Glib::File::Error,
41       Gtk2::Gdk::Pixbuf::Error, etc; these classes are provided by the
42       libraries that define the error domains.  However, it is possible to
43       get a base Glib::Error when the bindings encounter an unknown or
44       unbound error domain.  The interface used here degrades nicely in such
45       a situation, but in general you should submit a bug report to the
46       binding maintainer if you get such an exception.
47

METHODS

49   scalar = Glib::Error::new ($class, $code, $message)
50   scalar = $class->new ($code, $message)
51       ·   $code (Glib::Enum) an enumeration value, depends on $class
52
53       ·   $message (string)
54
55       Create a new exception object of type $class, where $class is
56       associated with a GError domain.  $code should be a value from the
57       enumeration type associated with this error domain.  $message can be
58       anything you like, but should explain what happened from the point of
59       view of a user.
60
61   integer = $error->code
62       This is the numeric error code.  Normally, you'll want to use "value"
63       instead, for readability.
64
65   string = $error->domain
66       The error domain.  You normally do not need this, as the object will be
67       blessed into a corresponding class.
68
69   string = $error->location
70       The source line and file closest to the emission of the exception, in
71       the same format that you'd get from croak() or die().
72
73       If there's non-ascii characters in the filename Perl leaves them as raw
74       bytes, so you may have to put the string through
75       Glib::filename_display_name for a wide-char form.
76
77   boolean = $error->matches ($domain, $code)
78       ·   $domain (string)
79
80       ·   $code (scalar)
81
82       Returns true if the exception in $error matches the given $domain and
83       $code.  $domain may be a class name or domain quark (that is, the real
84       string used in C).  $code may be an integer value or an enum nickname;
85       the enum type depends on the value of $domain.
86
87   string = $error->message
88       The error message.  This may be localized, as it is intended to be
89       shown to a user.
90
91   Glib::Error::register ($package, $enum_package)
92       ·   $package (string) class name to register as a Glib::Error.
93
94       ·   $enum_package (string) class name of the enum type to use for this
95           domain's error codes.
96
97       Register a new error domain.  Glib::Error will be added @package::ISA
98       for you.  enum_package must be a valid Glib::Enum type, either from a C
99       library or registered with "Glib::Type::register_enum".  After
100       registering an error domain, you can create or throw exceptions of this
101       type.
102
103   scalar = Glib::Error::throw ($class, $code, $message)
104   scalar = $class->throw ($code, $message)
105       ·   $code (Glib::Enum) an enumeration value, depends on $class
106
107       ·   $message (string)
108
109       Throw an exception with a Glib::Error exception object.  Equivalent to
110       "croak (Glib::Error::new ($class, $code, $message));".
111
112   string = $error->value
113       The enumeration value nickname of the integer value in "$error->code",
114       according to this error domain.  This will not be available if the
115       error object is a base Glib::Error, because the bindings will have no
116       idea how to get to the correct nickname.
117

SEE ALSO

119       Glib
120
122       Copyright (C) 2003-2009 by the gtk2-perl team.
123
124       This software is licensed under the LGPL.  See Glib for a full notice.
125
126
127
128perl v5.12.1                      2010-07-07                    Glib::Error(3)
Impressum