Java:标识符在catch语句中的作用是什么?
Java: what does the identifier do in the catch sentence?
我是编程新手。我正在学习 java,然后我找到了 try/catch。我非常理解 the 和概念,但我对 catch 语句有疑问:标识符在 catch 语句中的作用是什么?它是如何工作的?如何使用?
如有不明白:
public class Example {
public static void main (String[] args) {
try {
Integer.parseInt("m");
}catch (Exception e) {System.out.println("ERROR");} //This identifier (e)
}
}
可能答案很明显,但我想确定。
e
是您应该检查或至少打印的异常,以便您知道发生了什么错误、发生的错误以及可能的原因。添加
e.printStackTrace();
catch捕获异常e。这意味着异常 returns 是一个带有标识符 e 的异常对象。
这是由用户分配的,你可以做 catch
(异常捕获异常)。
异常有方法,可以在 catch 块中使用。例如
System.out.println(e)
将打印异常方法的详细信息。
我是编程新手。我正在学习 java,然后我找到了 try/catch。我非常理解 the 和概念,但我对 catch 语句有疑问:标识符在 catch 语句中的作用是什么?它是如何工作的?如何使用?
如有不明白:
public class Example {
public static void main (String[] args) {
try {
Integer.parseInt("m");
}catch (Exception e) {System.out.println("ERROR");} //This identifier (e)
}
}
可能答案很明显,但我想确定。
e
是您应该检查或至少打印的异常,以便您知道发生了什么错误、发生的错误以及可能的原因。添加
e.printStackTrace();
catch捕获异常e。这意味着异常 returns 是一个带有标识符 e 的异常对象。 这是由用户分配的,你可以做 catch (异常捕获异常)。 异常有方法,可以在 catch 块中使用。例如 System.out.println(e) 将打印异常方法的详细信息。