如何为整个类抛出一个异常,而不是通过方法来做这个方法 [英] How can I throw an exception for the whole class instead of doing it method by method

查看:151
本文介绍了如何为整个类抛出一个异常,而不是通过方法来做这个方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Java编写一个程序,我的一个课程中几乎所有的方法写成如下:

  public void doStuff()throws AWTException {} 

有没有办法摆脱额外的步骤的打字会为每个方法抛出AWTException,而不知怎么办呢?

解决方案

对不起,没有办法在Java中执行此操作。


I'm writing a program in Java, and nearly every method in one of my classes is written like:

public void doStuff() throws AWTException{}

Is there a way for me to get rid of the extra step of typing throws AWTException for each method, and somehow do it for the entire class?

解决方案

Sorry, No. There is no way to do this in Java.

这篇关于如何为整个类抛出一个异常,而不是通过方法来做这个方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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