gpt4 book ai didi

exception - 在 Perl 6 中,如何打印可能在编译时抛出的异常类型?

转载 作者:行者123 更新时间:2023-12-04 18:57:02 25 4
gpt4 key购买 nike

我正在尝试 solve this issue ,其中提到了 X::TypeCheck::Splice 的描述this page is wrong 中的异常.这是代码:

use experimental :macros;
CATCH {
# will definitely catch all the exception
default { say .^name, " → ", .Str; }
}

macro a { 'foo' };
say a;

我已经扩展到包括 CATCH堵塞。但是,抛出异常:

===SORRY!===
Too few positionals passed; expected 3 arguments but got 2

但是,我不知道它是否是正确的类型,因为它没有被 CATCH 块捕获。我也尝试将该块插入 CHECKBEGIN编译时出现的移相器无济于事。任何的想法?

显然,其他语言如 clojure let the macro handle its own exception .这在这里似乎行不通;在宏定义中插入 CATCH 块会引发警告和某种工作(将打印 Nil ),这可能意味着它正在捕获异常,但仍不打印异常类型。

最佳答案

通过 EVAL 运行您的代码将在 eval sub 的运行时抛出编译时警告

EVAL q/use experimental :macros; macro a { "foo" }; say a/;
CATCH { default { .perl.say } };
# X::AdHoc.new(payload => "Too few positionals passed; expected 3 arguments but got 2")

如您所见,至少在这个版本中,它是一个“无类型”异常。那些也可能来自 VM 内部,其中更细微的错误处理不像在 Perl 6 或 NQP 代码中那样容易。

关于exception - 在 Perl 6 中,如何打印可能在编译时抛出的异常类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50075490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com