Perl6:如何使所有警告致命? [英] Perl6: How could I make all warnings fatal?

查看:74
本文介绍了Perl6:如何使所有警告致命?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何使Perl6中的所有警告变为致命,以使脚本在屏幕上出现警告后立即消失。

How could I make all warnings in Perl6 fatal, so that the script dies as soon as a warning appears on the screen.

CONTROL {当CX :: Warn {注意$ _;退出1}} 死亡的频率更高。

此脚本在 CONTROL {时死亡,当CX :: Warn {注意$ _;退出1}} ,但不能与使用致命的

#!/usr/bin/env perl6
use v6;

my @a = 1 .. 4;
@a[5] = 6;
my @b;

for @a -> $i {
    @b.push( ~$i );
}

say "=====\n" x 3;


推荐答案

警告是 CX :: Warn 会默认恢复。如果要更改此行为,则需要添加一个 CONTROL 块,在这种情况下,应如下所示:

Warnings are control exceptions of type CX::Warn that are resumed by default. If you want to change that behaviour, you need to add a CONTROL block, in your case something like this:

CONTROL {
    when CX::Warn {
        note $_;
        exit 1;
    }
}

忽略所有警告而不是致命警告会像此:

Ignoring all warning instead of making them fatal would look like this:

CONTROL {
    when CX::Warn { .resume }
}

这篇关于Perl6:如何使所有警告致命?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆