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 }
}