1Net::DBus::Error(3) User Contributed Perl Documentation Net::DBus::Error(3)
2
3
4
6 Net::DBus::Error - Error details for remote method invocation
7
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
23 package Music::Player::Engine;
24
25 ...snip...
26
27 # Play either mp3 or ogg music tracks, otherwise
28 # thrown an error
29 sub play {
30 my $self = shift;
31 my $url = shift;
32
33 if ($url =~ /\.(mp3|ogg)$/) {
34 ...play the track
35 } else {
36 die Music::Player::UnknownFormat->new();
37 }
38 }
39
41 This objects provides for strongly typed error handling. Normally a
42 service would simply call
43
44 die "some message text"
45
46 When returning the error condition to the calling DBus client, the
47 message is associated with a generic error code or
48 "org.freedesktop.DBus.Failed". While this suffices for many
49 applications, occasionally it is desirable to be able to catch and
50 handle specific error conditions. For such scenarios the service should
51 create subclasses of the "Net::DBus::Error" object providing in a
52 custom error name. This error name is then sent back to the client
53 instead of the genreic "org.freedesktop.DBus.Failed" code.
54
56 my $error = Net::DBus::Error->new(name => $error_name, message =>
57 $description);
58 Creates a new error object whose name is given by the "name"
59 parameter, and long descriptive text is provided by the "message"
60 parameter. The "name" parameter has certain formatting rules which
61 must be adhered to. It must only contain the letters 'a'-'Z',
62 '0'-'9', '-', '_' and '.'. There must be at least two components
63 separated by a '.', For example a valid name is
64 'org.example.Music.UnknownFormat'.
65
66 $error->name
67 Returns the DBus error name associated with the object.
68
69 $error->message
70 Returns the descriptive text/message associated with the error
71 condition.
72
73 $error->stringify
74 Formats the error as a string in a manner suitable for printing out
75 / logging / displaying to the user, etc.
76
78 Daniel P. Berrange
79
81 Copyright (C) 2005-2011 Daniel P. Berrange
82
84 Net::DBus, Net::DBus::Object
85
86
87
88perl v5.34.0 2022-01-21 Net::DBus::Error(3)