unreported exception org.apache.commonms.configuration.ConfiguationException ;must be caught or declared to be thrown

huainansto 2008-03-20 12:03:24
private String target = getTarget();????unreported exception org.apache.commonms.configuration.ConfiguationException ;must be caught or declared to be thrown

public static String getTarget() throws ConfigurationException {
String target = "";
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL url = classLoader.getResource("org/seatore/resources/targetMachine.properties");
try {
Configuration config = new PropertiesConfiguration(url);
target = config.getString("target.ip");
logger.info("Connect to the machine:" + target);

}catch (ConfigurationException e) {

}
return target;
}
就是这句报错啊,而且我已经导入了
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.ConfigurationException;
请问这个是这么回事?
...全文
151 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
karlpan01 2008-03-20
  • 打赏
  • 举报
回复

public static String getTarget() throws ConfigurationException /*抛出异常?*/{
String target = "";
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL url = classLoader.getResource("org/seatore/resources/targetMachine.properties");
try /*捕获异常?*/{
Configuration config = new PropertiesConfiguration(url);
target = config.getString("target.ip");
logger.info("Connect to the machine:" + target);

}catch (ConfigurationException e) {

}
return target;
}


这样有什么意义么?
huainansto 2008-03-20
  • 打赏
  • 举报
回复
那要这么做??

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧