Idea: "throws" attribute for subs

Idea: "throws" attribute for subs

am 08.05.2007 10:30:58 von ifomichev

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 ;
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