如何处理IO :: socket :: inet中的例外?

发布于 2025-02-07 18:30:44 字数 306 浏览 1 评论 0原文

假设Localhost的端口12340没有侦听应用程序。

下面的命令不应该打印“错误”吗?

$ raku -e "IO::Socket::INET.new(:host('localhost'), :port(12340)) or die 'error'"
Could not connect socket: No connection could be made because the target machine actively refused it.

  in block <unit> at -e line 1

Assume there's no application listening at port 12340 in localhost.

Shouldn't the command below print "error" ?

$ raku -e "IO::Socket::INET.new(:host('localhost'), :port(12340)) or die 'error'"
Could not connect socket: No connection could be made because the target machine actively refused it.

  in block <unit> at -e line 1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

和我恋爱吧 2025-02-14 18:30:44

nqp ::连接的当前实现是建立连接的基础逻辑,将x :: adhoc异常。拥有io :: socket :: inet.new返回失败如果无法连接,对我来说确实更有意义。

我已经创建了一个拉请求创建此行为。

在此之前,您可以在本地使用相同的代码更改:

sub connect($host, $port) {
    CATCH { return .Failure }
    IO::Socket::INET.new(:$host, :$port)
}

connect('localhost', 12340) or die 'error';

The current implementation of nqp::connect, the underlying logic to make the connection, throws an X::AdHoc exception. Having IO::Socket::INET.new return a Failure if not able to connect, would make more sense to me indeed.

I've created a Pull Request to create this behaviour.

Until then, you can use the same code change locally:

sub connect($host, $port) {
    CATCH { return .Failure }
    IO::Socket::INET.new(:$host, :$port)
}

connect('localhost', 12340) or die 'error';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文