Class ErrorTypeMismatchException

All Implemented Interfaces:
Serializable

public class ErrorTypeMismatchException extends RuntimeException
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 Details

    • ErrorTypeMismatchException

      public ErrorTypeMismatchException(Class<? extends Throwable> expected, Throwable actual)