在创建custom exception class(例如自定义运行时异常)时,是否存在特定约定,以便在folder/package结构中创建它?
是否所有自定义异常类都在同一个包中?
我不熟悉错误/异常处理.这是怎么回事"引擎盖下"当一个例外是caught和thrown?
即在try-catch块中捕获异常然后抛出它有什么意义呢?
例如:
try {
//Stuff
} catch(StuffException e) {
throw new MyException();
}
}
Run Code Online (Sandbox Code Playgroud) 我在理解引发异常时会发生什么时遇到问题。
抛出的异常怎么办?是什么来确保程序不会崩溃?
例如,在本教程的本示例中,将如何处理ArithmeticException抛出的?
static int remainder(int dividend, int divisor)
throws DivideByZeroException {
try {
return dividend % divisor;
}
catch (ArithmeticException e) {
throw new DivideByZeroException();
}
}
Run Code Online (Sandbox Code Playgroud) 我已经安装了Java 8和设置我JAVA_HOME和JRE_HOME路径,并添加%JAVA_HOME%到开始path变量.
我创建了一个helloworld.java应用程序,并能够使用以下代码编译它:
javac helloworld.java
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行时:
java helloworld
我收到错误:
The system cannot find the file C:\ProgramData\Oracle\Java\javapath\java.exe
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?