这里为什么用按位或?
try
{
//some errorprone code
}
catch(NullPointerException |NumberFormatExceptioon e)
{
////handling the exception
}
最佳答案
在这种情况下,这不是按位运算符。这是捕获多个异常的语法。
Java 7 中添加的功能。
https://docs.oracle.com/javase/8/docs/technotes/guides/language/catch-multiple.html
The catch clause specifies the types of exceptions that the block can handle, and each exception type is separated with a vertical bar (|).
java 7之前,需要写
try{
//some errorprone code
}catch (NullPointerException ex) {
//handle
} catch (NumberFormatExceptioon ex) {
//handle
}
看,他们简化了它吧?
关于java - 为什么在catch block 中使用bitwise or来处理java中的异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32777379/