在java中如何让一个类既实现MouseListener又抛出IOException?
抛出 IOException 是针对来自文件的输入。
The throws IOException is for input from a file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
抛出 IOException 是针对来自文件的输入。
The throws IOException is for input from a file.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
像这样的东西:
something like this:
类不会引发异常,方法会引发异常。
Classes don't throw exceptions, methods do.
类不会抛出 IOException,而方法会。您的类可以实现 MouseListener,但这些方法(mouseClicked、mousePressed 等)不能抛出 IOException。您必须将它们包装在 RuntimeException (或子类)中。例如,
其他方法,例如
methodThatMightThrowAnIOException()
,可以抛出 IOException。Classes do not throw IOExceptions, methods do. Your class can implement MouseListener, but those methods (mouseClicked, mousePressed etc...) cannot throw IOExceptions. You'll have to wrap them in a RuntimeException (or a subclass). e.g.
Other methods, like
methodThatMightThrowAnIOException()
, can throw IOExceptions.