Package dev.kylesilver.result
Class ErrorTypeMismatchException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
dev.kylesilver.result.ErrorTypeMismatchException
- All Implemented Interfaces:
Serializable
This exception is thrown when the
Result.tryOr
function is unable to
cast a caught exception from the caller-provided CheckedSupplier
into
the desired error type. The existence of this class violates the principle of
least-surprise insofar as it is unchecked and can blow up during runtime,
which runs a bit counter to the idea that the Result
class wraps and
simplifies error handling. Unfortunately the existence of unchecked
exceptions means that any java function can blow up randomly for any reason,
so this is ultimately a losing battle. The only way to avoid ever
encountering this exception is to pass Throwable
as the expected type
to Result.tryOr(dev.kylesilver.result.CheckedSupplier<T, E>, java.lang.Class<E>)
, a move that would make any wrapped exceptions so
opaque that they would be practically meaningless.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionErrorTypeMismatchException
(Class<? extends Throwable> expected, Throwable actual) -
Method Summary
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
ErrorTypeMismatchException
-