public String ProcessA(String a) throws Throwable {
dosomething
}public String ProcessA(String a) throws Exception {
dosomething()
}public String ProcessA(String a) throws OwnException {
dosomething()
}那位大侠可以解释一下 上面三种对exception定义写法有什么不同 和应该在什么地方使用
dosomething
}public String ProcessA(String a) throws Exception {
dosomething()
}public String ProcessA(String a) throws OwnException {
dosomething()
}那位大侠可以解释一下 上面三种对exception定义写法有什么不同 和应该在什么地方使用
解决方案 »
- 就我这个没回复的,没人懂吗? Java JMF RTP 问题
- 【SOS】怎么产生1-100之间的100个不重复的随机整数才能效率高?
- filechooser.showOperDialog()那个dialog能修改吗?
- switch(),不是()里面的只能是int short byte char的么??
- 小弟在做scjp习题时遇到的一个问题……
- 有点问题没想明白
- 如何把做好的一个java application打包成exe文件啊
- 求助,打印三角形问题
- 请高手教我如何修改~~~
- 怎样得到当前日期的前两天??(在线等待)
- 打开src,想看看eventListerner里边写了点啥,结果一看,大吃一惊,什么也没有.这是为何???
- java中怎么取小数之前的数(例如13.0取13,123.0取123)?
楼主【winbug2008】截止到2008-07-02 21:08:07的历史汇总数据(不包括此帖):
发帖的总数量:0 发帖的总分数:0
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:0 未结的总分数:0
结贴的百分比:---------------------结分的百分比:---------------------
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
public String ProcessA(String a) throws Exception {
//dosomething()
}
如果没有声明此方法会抛出异常即
public String ProcessA(String a) {
//dosomething()
}
那么在ProcessA方法中如果使用到了别的会 抛出Exception子类的checked exception那么就必须用 try catch来处理,否则就必须在方法中声明要 throws Exception
对于 ProcessA能处理的异常,那么它可以自己用 try catch来处理,对于处理不了的异常或它不应该知道不应该处理得异常,就要向上抛出,由调用此方法的高层方法来处理。至于是throws Throwable throws Exception 或是 throws OwnException 那要看具体情况来定啊
一般情况下自己定义的 exception 都是继承与 RuntimeException的,都是unchecked exception不用 throws
我知道那是异常抛出声明。
就是我们在定义我的异常抛出声明的时候,上面三种写法是否会产生不同的结果。特别是Throwable,他和下面两种写法到底有什么区别呢?
谢谢大家了。
// Create a logger. For more information on the logging api's,
// see e385 The Quintessential Logging Program
Logger logger = Logger.getLogger("com.mycompany.mypackage");
BgThread() {
// As a daemon thread, this thread won't prevent the application from exiting
setDaemon(true);
}
// Set to true to shut down this thread
boolean stop = false;
public void run() {
while (!stop) {
try {
// Perform work here
} catch (Throwable t) {
// Log the exception and continue
logger.log(Level.SEVERE, "Unexception exception", t);
}
}
}
}
Don’t use throws Exception or throws ThrowableUsing throws Throwable and throws Exception subverts the exception checking system. If you do this, callers are forced to catch Throwable or Exception, which may catch both unchecked and checked exceptions. This forces callers to use instanceof to see whether the exception is one that they can deal with.Essentially, this defers the exception-checking mechanism from compile-time to runtime, which of course converts compile-time errors to runtime errors.On a related note, there’s not much point in specifying unchecked exception types in a throws clause, for example throws RuntimeException or throws NullPointerException. This serves no purpose except documentation, and it’s better to use a @throws javadoc comment for this, as you can include more information in the javadoc comment.
Quietly through .....