[perl #40123] [PROPOSAL] push_eh + .param for argument mismatch errors

Klaas-Jan Stol via RT parrotbug-followup at parrotcode.org
Sun Nov 30 13:14:10 UTC 2008


On Tue Aug 08 11:56:59 2006, mdiep wrote:
> Currently, if you want to use an exception handler to catch argument  
> mismatch errors inside of your subroutine, you need to use get_params:
> 
>    .sub foo
>        push_eh argument_mismatch
>            get_params '()'
>        clear_eh
> 
>        ...
>    .end
> 
> I'd really like to be able to use .param with this:
> 
>    .sub foo
>        push_eh argument_mismatch
>          .param pmc a
>          .param pmc b
>        clear_eh
> 
>        ...
>    argument_mismatch:
>        print "too few/many arguments to 'foo'\n"
>        end
>    .end
> 
>    .sub main :main
>        foo(1) # this would print the error and exit
>    .end
> 
> Ideally, I'd also be able to find out how many arguments were  
> actually passed (1 in this case).
> 
> --
> Matt Diephouse
> 

This issue is about 2 years old. Will there be some system in place to 
be able to catch parameter/argument mismatch exceptions?

(I would think the simplest solution is to have a wrapping sub, that 
invokes the sub that you would want to check, and in this wrapping sub 
you push/clear the eh., like so:

.sub wrapit
  .param pmc args :slurpy
  push_eh mismatch
  my_sub(args :flat)
  clear_eh
  .return ()
mismatch:
  print "argument mismatch!"
.end

Just an idea).

In any case, what's the status for this ticket? Still relevant?

Thanks!
kjs


More information about the parrot-dev mailing list