[Detroit-pm] Trying to get a handle on exceptions

Joe Landman landman at scalableinformatics.com
Thu May 22 12:29:58 PDT 2008


Scott Webster Wood wrote:
> OK, so you got this nifty little config file reader that reads some company's legacy config file format much better than their old scripted perl stuff did.  But when you made it, you were smart enough to put some error conditions that would either 'die' or 'croak' with Carp when things occurred that would prevent it from doing anything further (file not found, file not readable, etc) as well as the occasional carp that complains about things it finds that aren't quite kosher.
> 
> So you did it with a typical perl oop:
> 
> use readcfg;
> my $cfg = new readcfg(-cfgfile => 'somefile.cfg');

Out of curiousity, couldn't you:

	use readcfg;
	my $cfg;

	eval { $cfg = new readcfg(-cfgfile => 'somefile.cfg'); };

	if ($@)
	 {
	  # danger Will Robinson, handle the exception
	 }
	 else
	 {
	  # all is well in configuration land ...
	 }

> 
> ....

I seem to remember doing something like this in DBIx::SimplePerl and others.

-- 
Joseph Landman, Ph.D
Founder and CEO
Scalable Informatics LLC,
email: landman at scalableinformatics.com
web  : http://www.scalableinformatics.com
        http://jackrabbit.scalableinformatics.com
phone: +1 734 786 8423
fax  : +1 866 888 3112
cell : +1 734 612 4615


More information about the Detroit-pm mailing list