From Todd.Chapman at eprize.com Thu May 15 11:44:11 2008 From: Todd.Chapman at eprize.com (Todd Chapman) Date: Thu, 15 May 2008 14:44:11 -0400 Subject: [Detroit-pm] Detroit Perl Mongers Social Meeting, Tuesday May 20th, 8pm Message-ID: <64D0546C5EBBD147B75DE133D798665F7A7C46@hugo.eprize.local> This month Detroit.pm will be having a social meeting. Date: Tuesday May 20th, 8pm Location: the Blarney Stone pub http://www.theblarneystonepub.com/index.html We'll start at 8pm and go until whenever. All are welcome. (We are working on financing part of this event, but nothing has been secured yet. Be sure to bring $$$ for food and drink.) Any questions? Todd Chapman todd.chapman at eprize.com Software Engineer ePrize From Todd.Chapman at eprize.com Tue May 20 07:13:10 2008 From: Todd.Chapman at eprize.com (Todd Chapman) Date: Tue, 20 May 2008 10:13:10 -0400 Subject: [Detroit-pm] Reminder: Detroit.pm social tonight Message-ID: <64D0546C5EBBD147B75DE133D798665F7A7D31@hugo.eprize.local> This month Detroit.pm will be having a social meeting. Date: Tuesday May 20th, 8pm Location: the Blarney Stone pub http://www.theblarneystonepub.com/index.html We'll start at 8pm and go until whenever. All are welcome. (We are working on financing part of this event, but nothing has been secured yet. Be sure to bring $$$ for food and drink.) Any questions? Todd Chapman todd.chapman at eprize.com Software Engineer ePrize From treii28 at yahoo.com Thu May 22 12:23:49 2008 From: treii28 at yahoo.com (Scott Webster Wood) Date: Thu, 22 May 2008 12:23:49 -0700 (PDT) Subject: [Detroit-pm] Trying to get a handle on exceptions Message-ID: <733698.34532.qm@web38006.mail.mud.yahoo.com> 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'); .... but let's just say that I don't want the program calling the config reader to die when the read dies, but just to get an error condition back instead? I've been going over many websites but can't quite get my brain wrapped around the best way to handle this. I know if you call some of the built in stuff, they put the error stuff in errno in a nice nifty fashion that you can look up with $!. The platform I am working on isn't really going to allow me to add-in stuff like Error.pm, and I went to a bunch of sites using variations of try/catch or $SIG{__DIE__} but trying the examples they showed, I couldn't seem to get the same results that they suggested I should. Looking through my script it looks like there are only three fatal conditions. The object has a method 'init' that starts the actual read process. It requires a single parameter, a filename or filepath and does a single test '-f' to see if the file exists failing if it doesn't. It will then pass things off to a private method that actually parses the file but that begins by passing off to another simple method that just 'reads' a file. The other two fatals are in there, one being if no filename/filepath is passed to it at all (I also predict calling that method elsewhere so wanted to make sure again that there was a filename passed) and then the other croak is tied to the actual 'open' IO function itself. the new method also includes the ability to pass the -cfgfile => 'somefile' type context that will then run $self->init('somefile'), thus the syntax I gave above. So the big two that I am worried about are pretty much that 'init' gets a value that points to real file and that the file can be opened. my config reader dies in either of these two cases, but I don't want the program using the config reader to die when this happens. I know I can go in and pass error conditions back from the init, etc. but since I want to call init from new, it makes that difficult since 'new' is passing back the object itself. SW -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/detroit-pm/attachments/20080522/121d2619/attachment.html From landman at scalableinformatics.com Thu May 22 12:29:58 2008 From: landman at scalableinformatics.com (Joe Landman) Date: Thu, 22 May 2008 15:29:58 -0400 Subject: [Detroit-pm] Trying to get a handle on exceptions In-Reply-To: <733698.34532.qm@web38006.mail.mud.yahoo.com> References: <733698.34532.qm@web38006.mail.mud.yahoo.com> Message-ID: <4835C9B6.9030501@scalableinformatics.com> 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 From treii28 at yahoo.com Thu May 22 12:36:28 2008 From: treii28 at yahoo.com (Scott Webster Wood) Date: Thu, 22 May 2008 12:36:28 -0700 (PDT) Subject: [Detroit-pm] Trying to get a handle on exceptions Message-ID: <69741.61966.qm@web38007.mail.mud.yahoo.com> Yeah, I guess that's an option - I just don't like to use eval in web based apps for the most part. I figured there was probably some better way of handling it out there. SW ----- Original Message ---- From: Joe Landman To: Scott Webster Wood Cc: detroit-pm at pm.org Sent: Thursday, May 22, 2008 3:29:58 PM Subject: Re: [Detroit-pm] Trying to get a handle on exceptions 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