Custom exceptions in corda, should either derive from an appropriate closely related java exception, or CordaException, or CordaRuntimeException. They should not inherit just from Exception, or RuntimeException.

Handle PR comments

Add nicer constructors to CordaException and CordaRuntimeException

(cherry picked from commit 89478c8)

Fix ambiguous defaulted constructor

(cherry picked from commit ec9bafe)

Address PR comment

Update a few more custom exceptions
This commit is contained in:
Matthew Nesbit
2017-09-28 13:25:08 +01:00
parent d13bf77473
commit 5fa7381883
24 changed files with 68 additions and 44 deletions

View File

@ -67,7 +67,7 @@ class ThrowableSerializer(factory: SerializerFactory) : CustomSerializer.Proxy<T
logger.warn("Unexpected exception de-serializing throwable: ${proxy.exceptionClass}. Converting to CordaRuntimeException.", e)
}
// If the criteria are not met or we experience an exception constructing the exception, we fall back to our own unchecked exception.
return CordaRuntimeException(proxy.exceptionClass).apply {
return CordaRuntimeException(proxy.exceptionClass, null, null).apply {
this.setMessage(proxy.message)
this.setCause(proxy.cause)
this.stackTrace = proxy.stackTrace

View File

@ -1,11 +1,14 @@
package net.corda.nodeapi.internal.serialization.carpenter
class DuplicateNameException : RuntimeException(
import net.corda.core.CordaException
import net.corda.core.CordaRuntimeException
class DuplicateNameException : CordaRuntimeException(
"An attempt was made to register two classes with the same name within the same ClassCarpenter namespace.")
class InterfaceMismatchException(msg: String) : RuntimeException(msg)
class InterfaceMismatchException(msg: String) : CordaRuntimeException(msg)
class NullablePrimitiveException(msg: String) : RuntimeException(msg)
class NullablePrimitiveException(msg: String) : CordaRuntimeException(msg)
class UncarpentableException(name: String, field: String, type: String) :
Exception("Class $name is loadable yet contains field $field of unknown type $type")
CordaException("Class $name is loadable yet contains field $field of unknown type $type")