1BZ::Client::Exception(3U)ser Contributed Perl DocumentatiBoZn::Client::Exception(3)
2
3
4
6 BZ::Client::Exception - Exception class thrown by BZ::Client in case of
7 errors.
8
10 version 4.4004
11
13 BZ::Client does not return error codes or do similar stuff. Instead,
14 it throws instances of BZ::Client::Exception.
15
16 my $exception = BZ::Client::Exception->new( message => $message,
17 http_code => $httpCode,
18 xmlrpc_code => $xmlrpcCode );
19
20 BZ::Client::Exception->throw( message => $message,
21 http_code => $httpCode,
22 xmlrpc_code => $xmlrpcCode );
23
25 new
26 Creates the exception object
27
28 throw
29 Creates the exception object then dies, so make sure you catch it!
30
31 message
32 Returns the error message text
33
34 xmlrpc_code
35 Returns the error code from XMLRPC
36
37 http_code
38 Returns the http code (200, 404, etc)
39
41 Here are two examples. The first uses Perl's inbuilt eval() function,
42 the second uses the Try::Tiny module. Further alternatives exist and
43 may be perfectly good options if they suit you.
44
45 eval
46 use BZ::Client;
47 use BZ::Client::Bug::Attachment;
48 use v5.10;
49
50 my $client = BZ::Client->new( %etc );
51
52 eval {
53 my $att = BZ::Client::Bug::Attachment->get($client, { ids => 30505 });
54 };
55
56 if ($@) {
57 say 'An Error Occured';
58 say 'Message: ', $@->message();
59 say 'HTTP Code: ', $@->http_code() if $@->http_code();
60 say 'XMLrpc Code: ', $@->xmlrpc_code() if $@->xmlrpc_code();
61 };
62
63 Try::Tiny
64 use BZ::Client;
65 use BZ::Client::Bug::Attachment;
66 use Try::Tiny;
67 use v5.10;
68
69 my $client = BZ::Client->new( %etc );
70
71 try {
72 my $att = BZ::Client::Bug::Attachment->get($client, { ids => 30505 });
73 }
74
75 catch {
76 say 'An Error Occured';
77 say 'Message: ', $_->message();
78 say 'HTTP Code: ', $_->http_code() if $_->http_code();
79 say 'XMLrpc Code: ', $_->xmlrpc_code() if $_->xmlrpc_code();
80 };
81
83 BZ::Client
84
86 • Dean Hamstead <dean@bytefoundry.com.au>
87
88 • Jochen Wiedmann <jochen.wiedmann@gmail.com>
89
91 This software is copyright (c) 2021 by Dean Hamstad.
92
93 This is free software; you can redistribute it and/or modify it under
94 the same terms as the Perl 5 programming language system itself.
95
96
97
98perl v5.36.0 2023-01-20 BZ::Client::Exception(3)