File: error.pl

package info (click to toggle)
libgnome2-gconf-perl 1.044-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 248 kB
  • ctags: 37
  • sloc: perl: 563; makefile: 52; ansic: 32
file content (49 lines) | stat: -rw-r--r-- 1,032 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl
# GConf Error test using Glib::Error.
# Copyright 2004 Emmanuele Bassi
# Released under the terms of the GNU General Public License.

use strict;
use warnings;
use Gnome2::GConf;

our $client = Gnome2::GConf::Client->get_default;

# try:
eval
{
	# if you ran the basic/complex gconf apps inside the examples/ directory,
	# this call should not fail.
	print $client->get_string('/apps/basic-gconf-app/foo') . "\n";
	
	# this call, on the other hand, will always fail.
	print $client->get_string('/apps/basic-gconf-app/') . "\n";

	1;
};
# catch:
if ($@)
{
	use Data::Dumper;
	use Glib;
	
	# catch Gnome2::GConf::Error
	if ($@->isa('Gnome2::GConf::Error'))
	{
		print "Catching a Gnome2::GConf::Error exception...\n";
		if (Glib::Error::matches($@, 'Gnome2::GConf::Error', 'bad-key'))
		{
			# print message...
			print "*** Our catched error:\n" . $@->message . "\n";
			
			# ...and recover from the 'bad-key' error.
		}
	}

	# this is always valid
	print "*** GConf error:\n$@\n";
	
	print Dumper($@) . "\n";
}

0;