find_name doesn't obey docs on unbound

Jonathan Worthington jonathan at jnthn.net
Fri Feb 19 11:41:22 UTC 2010


Jonathan Leto wrote:
> I am talkign to Perry at PDX Hackathon, and the example code that does
> not work should be:
>
>     .include 'errors.pasm'
> .sub main :main  ### :pedantic_args
>        .param string argv :slurpy
>        errorson .PARROT_ERRORS_GLOBALS_FLAG
>        push_eh myhandler
>        $P0 = find_name "i_better_not_exist_or_this_thing_is_crazy"
>        pop_eh
>        if null $P0 goto wasnull
>        say "not null, must have existed somehow.   inconceivable!"
>        exit 1
> wasnull:
>        say "was null.   not good!"
>        exit 2
> myhandler:
>        pop_eh
>        say "generated exception.   excellent!"
>        exit 0
> .end
>
>
> Note that errors.pasm had to be included, errorson does not have
> parens and a few pop_eh's need to be sprinkled in.
>
>   
Many Parrot ops return null when things aren't found (e.g. 
get_hll_global). My preference would be to keep this op doing that by 
default rather than throwing exceptions by default, since while it's 
cheap for a language that wants an exception to say "is it null" and 
throw one, it's more expensive for those that don't want one (quite 
common) to catch the exception and do some kind of auto-vivification.

Maybe the error flags thing could be set up as a way to enable Parrot to 
throw the exceptions for you, but...

* The flag has to be checked on a hot path - looking up 
variables/functions/etc, so it hurts all languages a little performance 
wise, whichever semantics they want.

* Unless there's a way to say what sort of exception to throw, it's 
probably not so useful for many languages, since languages will likely 
have their own exception classes/types that they want throwing.

Thanks,

Jonathan



More information about the parrot-dev mailing list