home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / perl5 / Glib / Error.pod < prev    next >
Encoding:
Text File  |  2006-06-19  |  4.8 KB  |  231 lines

  1. =head1 NAME
  2.  
  3. Glib::Error -  Exception Objects based on GError
  4.  
  5. =for position SYNOPSIS
  6.  
  7. =head1 SYNOPSIS
  8.  
  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.  
  26. =cut
  27.  
  28.  
  29.  
  30. =for position DESCRIPTION
  31.  
  32. =head1 DESCRIPTION
  33.  
  34. Gtk2-Perl translates GLib's GError runtime errors into Perl exceptions, by
  35. creating exception objects based on Glib::Error.  Glib::Error overloads the
  36. stringification operator, so a Glib::Error object will act like a string if
  37. used with print() or warn(), so most code using $@ will not even know the
  38. difference.
  39.  
  40. The point of having exception objects, however, is that the error messages
  41. in GErrors are often localized with NLS translation.  Thus, it's not good
  42. for your code to attempt to handle errors by string matching on the the 
  43. error message.  Glib::Error provides a way to get to the deterministic
  44. error code.
  45.  
  46. You will typically deal with objects that inherit from Glib::Error, such as
  47. Glib::Convert::Error, Glib::File::Error, Gtk2::Gdk::Pixbuf::Error, etc; these
  48. classes are provided by the libraries that define the error domains.  However,
  49. it is possible to get a base Glib::Error when the bindings encounter an unknown
  50. or unbound error domain.  The interface used here degrades nicely in such a
  51. situation, but in general you should submit a bug report to the binding
  52. maintainer if you get such an exception.
  53.  
  54. =cut
  55.  
  56.  
  57.  
  58. =for object Glib::Error Exception Objects based on GError
  59. =cut
  60.  
  61.  
  62.  
  63.  
  64. =head1 METHODS
  65.  
  66. =head2 scalar = Glib::Error::new ($class, $code, $message)
  67.  
  68. =head2 scalar = $class->B<new> ($code, $message)
  69.  
  70. =over
  71.  
  72. =over
  73.  
  74. =item * $code (GEnum) an enumeration value, depends on I<$class>
  75.  
  76. =item * $message (string) 
  77.  
  78. =back
  79.  
  80.  
  81. Create a new exception object of type I<$class>, where I<$class> is associated
  82. with a GError domain.  I<$code> should be a value from the enumeration type
  83. associated with this error domain.  I<$message> can be anything you like, but
  84. should explain what happened from the point of view of a user.
  85.  
  86.  
  87. =back
  88.  
  89. =head2 integer = $error-E<gt>B<code> 
  90.  
  91. =over
  92.  
  93.  
  94. This is the numeric error code.  Normally, you'll want to use C<value> instead,
  95. for readability.
  96.  
  97.  
  98. =back
  99.  
  100. =head2 string = $error-E<gt>B<domain> 
  101.  
  102. =over
  103.  
  104.  
  105. The error domain.  You normally do not need this, as the object will be blessed
  106. into a corresponding class.
  107.  
  108.  
  109. =back
  110.  
  111. =head2 string = $error-E<gt>B<location> 
  112.  
  113. =over
  114.  
  115.  
  116. The source line and file closest to the emission of the exception, in the same
  117. format that you'd get from croak() or die().
  118.  
  119.  
  120. =back
  121.  
  122. =head2 boolean = $error-E<gt>B<matches> ($domain, $code)
  123.  
  124. =over
  125.  
  126. =over
  127.  
  128. =item * $domain (string) 
  129.  
  130. =item * $code (scalar) 
  131.  
  132. =back
  133.  
  134. Returns true if the exception in I<$error> matches the given I<$domain> and
  135. I<$code>.  I<$domain> may be a class name or domain quark (that is, the real
  136. string used in C).  I<$code> may be an integer value or an enum nickname;
  137. the enum type depends on the value of I<$domain>.
  138.  
  139. =back
  140.  
  141. =head2 string = $error-E<gt>B<message> 
  142.  
  143. =over
  144.  
  145.  
  146. The error message.  This may be localized, as it is intended to be shown to a
  147. user.
  148.  
  149.  
  150. =back
  151.  
  152. =head2 Glib::Error::register ($package, $enum_package)
  153.  
  154. =over
  155.  
  156. =over
  157.  
  158. =item * $package (string) class name to register as a Glib::Error.
  159.  
  160. =item * $enum_package (string) class name of the enum type to use for this domain's error codes.
  161.  
  162. =back
  163.  
  164. Register a new error domain.  Glib::Error will be added @I<package>::ISA for
  165. you.  I<enum_package> must be a valid Glib::Enum type, either from a C library
  166. or registered with C<< Glib::Type::register_enum >>.  After registering an
  167. error domain, you can create or throw exceptions of this type.
  168.  
  169. =back
  170.  
  171. =head2 scalar = Glib::Error::throw ($class, $code, $message)
  172.  
  173. =head2 scalar = $class->B<throw> ($code, $message)
  174.  
  175. =over
  176.  
  177. =over
  178.  
  179. =item * $code (GEnum) an enumeration value, depends on I<$class>
  180.  
  181. =item * $message (string) 
  182.  
  183. =back
  184.  
  185.  
  186. Throw an exception with a Glib::Error exception object.
  187. Equivalent to C<< croak (Glib::Error::new ($class, $code, $message)); >>.
  188.  
  189.  
  190. =back
  191.  
  192. =head2 string = $error-E<gt>B<value> 
  193.  
  194. =over
  195.  
  196.  
  197. The enumeration value nickname of the integer value in C<< $error->code >>, 
  198. according to this error domain.  This will not be available if the error
  199. object is a base Glib::Error, because the bindings will have no idea how to
  200. get to the correct nickname.
  201.  
  202.  
  203. =back
  204.  
  205.  
  206. =head1 ENUMS AND FLAGS
  207.  
  208. =head2 enum GEnum
  209.  
  210. =over
  211.  
  212.  
  213.  
  214. =back
  215.  
  216.  
  217.  
  218. =head1 SEE ALSO
  219.  
  220. L<Glib>
  221.  
  222. =head1 COPYRIGHT
  223.  
  224. Copyright (C) 2003-2005 by the gtk2-perl team.
  225.  
  226. This software is licensed under the LGPL.  See L<Glib> for a full notice.
  227.  
  228.  
  229. =cut
  230.  
  231.