man-pages/man3/Net::DBus::Error.3pm.html
2021-03-31 01:06:50 +01:00

163 lines
3.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of Net::DBus::Error</TITLE>
</HEAD><BODY>
<H1>Net::DBus::Error</H1>
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2019-12-26<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
Net::DBus::Error - Error details for remote method invocation
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
package Music::Player::UnknownFormat;
use base qw(Net::DBus::Error);
# Define an error type for unknown track encoding type
# for a music player service
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = $class-&gt;SUPER::new(name =&gt; &quot;org.example.music.UnknownFormat&quot;,
message =&gt; &quot;Unknown track encoding format&quot;);
}
package Music::Player::Engine;
...snip...
# Play either mp3 or ogg music tracks, otherwise
# thrown an error
sub play {
my $self = shift;
my $url = shift;
if ($url =~ /\.(mp3|ogg)$/) {
...play the track
} else {
die Music::Player::UnknownFormat-&gt;new();
}
}
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
This objects provides for strongly typed error handling. Normally
a service would simply call
<P>
<PRE>
die &quot;some message text&quot;
</PRE>
<P>
When returning the error condition to the calling DBus client, the
message is associated with a generic error code or ``org.freedesktop.DBus.Failed''.
While this suffices for many applications, occasionally it is desirable
to be able to catch and handle specific error conditions. For such
scenarios the service should create subclasses of the <TT>&quot;Net::DBus::Error&quot;</TT>
object providing in a custom error name. This error name is then sent back
to the client instead of the genreic ``org.freedesktop.DBus.Failed'' code.
<A NAME="lbAE">&nbsp;</A>
<H2>METHODS</H2>
<DL COMPACT>
<DT id="1">my $error = Net::DBus::Error-&gt;new(name =&gt; $error_name, message =&gt; $description);<DD>
Creates a new error object whose name is given by the <TT>&quot;name&quot;</TT>
parameter, and long descriptive text is provided by the
<TT>&quot;message&quot;</TT> parameter. The <TT>&quot;name&quot;</TT> parameter has certain
formatting rules which must be adhered to. It must only contain
the letters 'a'-'Z', '0'-'9', '-', '_' and '.'. There must be
at least two components separated by a '.', For example a valid
name is 'org.example.Music.UnknownFormat'.
<DT id="2">$error-&gt;name<DD>
Returns the DBus error name associated with the object.
<DT id="3">$error-&gt;message<DD>
Returns the descriptive text/message associated with the
error condition.
<DT id="4">$error-&gt;stringify<DD>
Formats the error as a string in a manner suitable for
printing out / logging / displaying to the user, etc.
</DL>
<A NAME="lbAF">&nbsp;</A>
<H2>AUTHOR</H2>
Daniel P. Berrange
<A NAME="lbAG">&nbsp;</A>
<H2>COPYRIGHT</H2>
Copyright (C) 2005-2011 Daniel P. Berrange
<A NAME="lbAH">&nbsp;</A>
<H2>SEE ALSO</H2>
Net::DBus, Net::DBus::Object
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="5"><A HREF="#lbAB">NAME</A><DD>
<DT id="6"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="7"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="8"><A HREF="#lbAE">METHODS</A><DD>
<DT id="9"><A HREF="#lbAF">AUTHOR</A><DD>
<DT id="10"><A HREF="#lbAG">COPYRIGHT</A><DD>
<DT id="11"><A HREF="#lbAH">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:49 GMT, March 31, 2021
</BODY>
</HTML>