<commit_before>my class Failure {
    has $!exception;
    has $!handled;

    method new($ex) {
        my $new = self.CREATE;
        $new.BUILD($ex);
    }

    method BUILD($ex) {
        $!exception = $ex;
        self;
    }

    # TODO: should be Failure:D: multi just like method Bool,
    # but obscure problems prevent us from making Mu.defined
    # a multi. See http://irclog.perlgeek.de/perl6/2011-06-28#i_4016747
    method defined() {
        $!handled =1 if pir::repr_defined__IP(self);
        Bool::False;
    }
    multi method Bool(Failure:D:) { $!handled = 1; Bool::False; }

    method Int(Failure:D:) { $!handled ?? 0 !! $!exception.rethrow; }
    method Num(Failure:D:) { $!handled ?? 0e0 !! $!exception.rethrow; }
    multi method Str(Failure:D:) { $!handled ?? '' !! $!exception.rethrow; }
}


my &fail := -> *@msg {
    my $value = @msg.join('');
    my Mu $ex := Q:PIR {
                     # throw and immediately catch an exception, to capture
                     # the location at the point of the fail()
                     push_eh catch
                     $P0 = find_lex '$value'
                     $S0 = $P0
                     die $S0<commit_msg>throw an exception when calling an exception of Failure<commit_after>my class Failure {
    has $!exception;
    has $!handled;

    method new($ex) {
        my $new = self.CREATE;
        $new.BUILD($ex);
    }

    method BUILD($ex) {
        $!exception = $ex;
        self;
    }

    # TODO: should be Failure:D: multi just like method Bool,
    # but obscure problems prevent us from making Mu.defined
    # a multi. See http://irclog.perlgeek.de/perl6/2011-06-28#i_4016747
    method defined() {
        $!handled =1 if pir::repr_defined__IP(self);
        Bool::False;
    }
    multi method Bool(Failure:D:) { $!handled = 1; Bool::False; }

    method Int(Failure:D:) { $!handled ?? 0 !! $!exception.rethrow; }
    method Num(Failure:D:) { $!handled ?? 0e0 !! $!exception.rethrow; }
    multi method Str(Failure:D:) { $!handled ?? '' !! $!exception.rethrow; }

    Failure.^add_fallback(
        -> $, $ { True },
        method ($name) {
            die $!exception;
        }
    );
}


my &fail := -> *@msg {
    my $value = @msg.join('');
    my Mu $ex := Q:PIR {
                     # throw and immediately catch an exception, to capture
                     # the location at the point of the fail()
                     push_eh catch
                     $P0 = find_lex '$value'
                     $S0 = $P0
                     die $S0
{'fraction_non_alphanumeric': 0.1418467583497053, 'fraction_numerical': 0.019646365422396856, 'mean_word_length': 1.893181818181818, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7107749', 'n_tokens_mistral': 872, 'n_tokens_neox': 796, 'n_words': 217}