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

In Perl 6, how can I print the type of Exceptions thrown, possibly at compile time?

我正在尝试 solve this issue, which mentions that the description of X::TypeCheck::Splice exception in 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")

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