develooper Front page | perl.perl6.language | Postings from January 2010

Custom errors on subsets?

Thread Next
From:
Ovid
Date:
January 4, 2010 05:15
Subject:
Custom errors on subsets?
Message ID:
629754.25438.qm@web65705.mail.ac4.yahoo.com
Given this code:

    subset Filename of Str where { $_ ~~ :f };

    sub foo (Filename $name) {
        say "Houston, we have a filename: $name";
    }

    my Filename $foo = $*EXECUTABLE_NAME;
    foo($foo);
    foo($*EXECUTABLE_NAME);
    foo('no_such_file');

We get this output:

    Houston, we have a filename: /Users/ovid/bin/perl6
    Houston, we have a filename: /Users/ovid/bin/perl6
    Constraint type check failed for parameter '$name'
    in Main (file src/gen_setting.pm, line 324)

Obviously the error message can use some work, but how would I customize that error message (assuming such will be possible in the future)?  Clearly there will be many cases where a custom error message for constraint failure could make life much easier for developers.

Cheers,
Ovid
--
Buy the book         - http://www.oreilly.com/catalog/perlhks/
Tech blog            - http://use.perl.org/~Ovid/journal/
Twitter              - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About