如何在球拍中实现try-catch块?

发布于 2025-02-10 21:05:07 字数 963 浏览 2 评论 0原文

我尝试在球拍中写下try-catch块,从提供的样板中,提供在这里,但是当我运行时,它会给我带来错误。

try-catch块:

#lang racket
 (require try-catch-match)


(try [(displayln "body")
    (raise 'boom)]
   [catch (string? (printf "caught a string: ~v\n" e))
          (symbol? (printf "'e' (the value of the exception) is: ~v\n" e))])

引发此错误:

< img src =“ https://i.sstatic.net/6acoz.jpg” alt =“在此处输入图像说明”>

它说语法错误,但我真的看不到任何问题。该代码来自官方球拍网站。我的目标是在球拍中写一个简单的try-catch块,大概是使用导入的库。

I try to write a try-catch block in racket, from the boilerplate provided here, however when I run it throws me an error.

try-catch block:

#lang racket
 (require try-catch-match)


(try [(displayln "body")
    (raise 'boom)]
   [catch (string? (printf "caught a string: ~v\n" e))
          (symbol? (printf "'e' (the value of the exception) is: ~v\n" e))])

Throws this error:

enter image description here

It says syntax error, but I really cannot see any issues. The code is from the official racket website. My goal is to write a simple try-catch block in racket, presumably using the imported library.

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

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

发布评论

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

评论(1

东北女汉子 2025-02-17 21:05:09

您需要 try-catch-match-match 库,但是您的示例来自 try-catch 库。这两个是不同的,如果您使用正确的一个,则示例代码将有效:

#lang racket
(require try-catch)

(try [(displayln "body")
        (raise 'boom)]
       [catch (string? (printf "caught a string\n"))
              (symbol? (printf "caught a symbol\n"))])

You're requiring try-catch-match library, but your example comes from try-catch library. These two are different and if you use the correct one, the example code will work:

#lang racket
(require try-catch)

(try [(displayln "body")
        (raise 'boom)]
       [catch (string? (printf "caught a string\n"))
              (symbol? (printf "caught a symbol\n"))])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文