控制 - Java 中的 C 异常
我需要捕获该异常,但我不知道它是哪一个。我现在使用的 IDE 不允许这样的程序中断。
我知道如何使用 try/catch,但我实际上不知道我要捕获什么。
任何人都可以帮助我吗?
I need to catch that exception but I can't figure out which one it is. The IDE i'm using right now doesn't allow for a program interrupt that way.
I know how to user try/catch, but I don't actually know what I'm trying to catch..
Can anyone help me with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我似乎记得 CTRL-C 变成了 InterruptedException 并且这篇 文章似乎支持这一点。正如其他答案中所建议的,使用
addShutdownHook
是一个好方法,除非您想阻止关闭。I seem to recall that CTRL-C becomes an InterruptedException and this article seems to support that. As suggested in other answers the use of
addShutdownHook
is a good way to go, unless you want to prevent the shutdown.听起来你需要
Runtime.addShutdownHook()
我不确定您是否真的可以捕获它,您只需提供一个在虚拟机关闭时运行的
Thread
即可。我认为一旦开始你就无法阻止它。Sounds like you need
Runtime.addShutdownHook()
I'm not sure if you can actually catch it as such, you just supply a
Thread
to be run when the VM is shutting down. I don't think you can stop it once this kicks off.addShutdownHook() 就是你想要的。
http://www.esus.com/javaindex/j2se/ jdk1.2/javalang/trapctrlc.html
addShutdownHook() is what you want.
http://www.esus.com/javaindex/j2se/jdk1.2/javalang/trapctrlc.html