Click here to get back home

Idea: 'throws' attribute for subs

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Idea: 'throws' attribute for subs ifomichev 05-08-2007
Posted by ifomichev on May 8, 2007, 4:30 am
Please log in for more thread options


Greetings, colleagues!

I'm going to begin working on an extension, that would introduce an
attribute for subroutines, somewhat similar to Java's 'throws'.

It could like something like <<'__THE_FOLLOWING__':
use <TheModule>;
use Exception::Class (
'Danger',
'Danger::Avalanche' => { isa => 'Danger' },
'Danger::Tornado' => { isa => 'Danger' },
);

sub dangerous : throws(Danger'Avalanche,Danger'Tornado) { }
__THE_FOLLOWING__

If 'dangerous' is called from somewhere else and Danger::Avalanche and
Danger::Tornado (or any ancestor exception class, i. e. Danger or
Exception::Class) are not being caught,
then an exception like <<'__THIS__' will be thrown:
Exceptions 'Danger::Avalanche', 'Danger::Tornado' are not being caught
at badcode.pl line 8
__THIS__

I've got a couple of questions:
1. Is there something like this already available?
2. What name for 'TheModule' can you suggest?
3. Any ideas how to make 'exception not being caught' exception be
thrown during the compilation phase, to make sure all thrown
exceptions are caught in the code, even if some subroutines are not
called afterwards during the execution? In other words, do you see a
way how to get the stack of subroutine calls during the compilation
phase, not waiting for subroutines are really executed?

Regards,
Ivan


Similar ThreadsPosted
Retrieving XML attribute using XML::XPath::Node::Attribute June 28, 2005, 5:02 am
New OO module idea - looking for suggestions October 1, 2007, 11:26 pm
Text::Balanced to extract subs? June 15, 2006, 10:35 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap