我是C程序员,最近刚学习一些java,因为我正在开发一个android应用程序。目前我处于一种状况。以下是一个。如何在java中传播异常
public Class ClassA{
public ClassA();
public void MyMethod(){
try{
//Some code here which can throw exceptions
}
catch(ExceptionType1 Excp1){
//Here I want to show one alert Dialog box for the exception occured for the user.
//but I am not able to show dialog in this context. So I want to propagate it
//to the caller of this method.
}
catch(ExceptionType2 Excp2){
//Here I want to show one alert Dialog box for the exception occured for the user.
//but I am not able to show dialog in this context. So I want to propagate it
//to the caller of this method.
}
}
}
现在我想在另一个类的其他地方调用方法MyMethod()。如果有人可以提供一些代码片段,以便如何将异常传播给MyMethod()的调用者,以便我可以在调用方法的对话框中显示它们。
对不起如果我不是那么清楚和怪异的问这个问题的方式。
参见http://stackoverflow.com/questions/409563/best-prac tices换异常管理功能于Java的或-C-尖锐 – mglauche 2012-02-29 12:34:45