我为我的应用程序不期望的每个条件创建了异常. UserNameNotValidException,PasswordNotCorrectException等等.
但是我被告知我不应该为这些条件创建例外.在我的UML中,那些是主流的例外,为什么它不应该是例外?
创建例外的任何指导或最佳实践?
在这里提供了一些答案并阅读了一些注释后,似乎实际上IOException永远不会在文件I/O上关闭.
是否有任何情况下,在Stream/Reader/Writer上调用close实际上会抛出IOException?
如果实际抛出异常,应如何处理?
我不明白在代码中使用链式异常的优点.
考虑来自java世界的ResourceLoader示例,如果程序员知道遇到的可能性ResourceLoadException,为什么不捕获相同的异常而不是SQLException?另外,程序员可以捕获相同代码中的异常,而不是抛出新Throwable实例?
我是一名C程序员,最近刚刚学习了一些java,因为我正在开发一个Android应用程序.目前我处于这种情况.以下是一个.
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 …Run Code Online (Sandbox Code Playgroud)