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

NAME

6       Net::DBus::Error - Error details for remote method invocation
7

SYNOPSIS

9         package Music::Player::UnknownFormat;
10
11         use base qw(Net::DBus::Error);
12
13         # Define an error type for unknown track encoding type
14         # for a music player service
15         sub new {
16             my $proto = shift;
17             my $class = ref($proto) ⎪⎪ $proto;
18             my $self = $class->SUPER::new(name => "org.example.music.UnknownFormat",
19                                           message => "Unknown track encoding format");
20         }
21
22         package Music::Player::Engine;
23
24         ...snip...
25
26         # Play either mp3 or ogg music tracks, otherwise
27         # thrown an error
28         sub play {
29             my $self = shift;
30             my $url = shift;
31
32             if ($url =~ /\.(mp3⎪ogg)$/) {
33                 ...play the track
34             } else {
35                die Music::Player::UnknownFormat->new();
36             }
37         }
38

DESCRIPTION

40       This objects provides for strongly typed error handling. Normally a
41       service would simply call
42
43         die "some message text"
44
45       When returning the error condition to the calling DBus client, the mes‐
46       sage is associated with a generic error code or "org.freedesk‐
47       top.DBus.Failed".  While this suffices for many applications, occasion‐
48       ally it is desirable to be able to catch and handle specific error con‐
49       ditions. For such scenarios the service should create subclasses of the
50       "Net::DBus::Error" object providing in a custom error name. This error
51       name is then sent back to the client instead of the genreic
52       "org.freedesktop.DBus.Failed" code.
53

METHODS

55       my $error = Net::DBus::Error->new(name => $error_name, message =>
56       $description);
57           Creates a new error object whose name is given by the "name" param‐
58           eter, and long descriptive text is provided by the "message" param‐
59           eter. The "name" parameter has certain formatting rules which must
60           be adhered to. It must only contain the letters 'a'-'Z', '0'-'9',
61           '-', '_' and '.'. There must be at least two components separated
62           by a '.', For example a valid name is 'org.example.Music.Unknown‐
63           Format'.
64
65       $error->name
66           Returns the DBus error name associated with the object.
67
68       $error->message
69           Returns the descriptive text/message associated with the error con‐
70           dition.
71
72       $error->stringify
73           Formats the error as a string in a manner suitable for printing out
74           / logging / displaying to the user, etc.
75

AUTHORS

77       Daniel P. Berrange
78
80       Copyright (C) 2005-2006 Daniel P. Berrange
81

SEE ALSO

83       Net::DBus, Net::DBus::Object
84
85
86
87perl v5.8.8                       2008-02-20               Net::DBus::Error(3)
Impressum