确定球拍程序是否在沙箱中 [英] Determin if a racket program is in a sandbox

查看:62
本文介绍了确定球拍程序是否在沙箱中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以确定在沙箱中是否正在运行Racket程序?

Is it possible to determine if a Racket program is being run in a sandbox?

我问的原因是因为我有一个创建文件的Racket宏.而且DrRacket后台扩展程序可以防止创建文件(应如此).但是,这样做会导致错误显示在窗口底部,表明无法创建文件.

The reason I ask is because I have a Racket macro that creates a file. And the DrRacket background expander prevents a file from being created (as it should). However, in doing so, it causes an error to appear at the bottom of the window saying the file could not be created.

因此,我想确定我是否在沙箱中,如果我不在,请不要创建文件,请完成宏.

So, I would like to determine if I am in a sandbox, and if I am, don't create the file, and kindly finish up the macro.

推荐答案

通常,您无法确定自己是否在沙箱中.但是,您确实有机会捕获尝试执行受限操作时引发的错误.但是,要注意的是,您不知道将要引发哪种类型的错误.因此,您可以做的一件事就是只抓住所有的人.使用

In general, you cannot determine if you are in a sandbox. However, you do have a chance to catch the errors that are thrown when you try to perform a restricted operation. However, the catch is that you do not know what type of error is going to be thrown. So one thing that you can do is to just catch all of them. Use with-handlers to catch the error and exn:fail? to catch all errors.

(with-handlers ([exn:fail?
                 (lambda (x) (displayln "failing cleanly"))])
    (make-temporary-file))

请注意此处可能会发生与沙盒无关的错误.例如,您可能仅由于无法创建文件而得到错误:

Be careful here that an error here may occur that is not related to being in a sandbox. For example, you could potentially get an error just because a file could not be created:

(with-handlers ([exn:fail:filesystem?
                 (lambda (x) (displayln "Coudln't open file"))]
                [exn:fail?
                 (lambda (x) (displayln "failing gracefully"))])
  (make-temporary-file))

这篇关于确定球拍程序是否在沙箱中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆