Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 正在尝试从exception.cause获取嵌套异常_Java_Exception_Kotlin - Fatal编程技术网

Java 正在尝试从exception.cause获取嵌套异常

Java 正在尝试从exception.cause获取嵌套异常,java,exception,kotlin,Java,Exception,Kotlin,我有一个try-catch块,如下所示: try { code that may throw an exception } catch (e: DataIntegrityException) { val cause = e.cause //prints "Is the cause a ConstraintViolationException: false" println("Is the cause a ConstraintViolationException: " (c

我有一个try-catch块,如下所示:

try {

  code that may throw an exception

} catch (e: DataIntegrityException) {

  val cause = e.cause

  //prints "Is the cause a ConstraintViolationException: false"
  println("Is the cause a ConstraintViolationException: " (cause is ConstraintViolationException))

  //prints org.hibernate.exception.ConstraintViolationException
  println(cause)

  //Here I want to do something with a ConstraintViolationException.

}
我捕获的DataIntegrityException有一个嵌套的ConstraintViolationException,我需要使用
cause.constraintViolations

我已尝试直接捕获ConstraintViolationException,但由于它位于DataIntegrityViolation内,因此不会触发捕获


println(cause)
表明它是一个ConstraintViolationException时,我很困惑为什么
(cause是ConstraintViolationException)
的计算结果是
false
?请注意,还有一个…是的!谢谢,有两个同名的进口货