cyclops-integration icon indicating copy to clipboard operation
cyclops-integration copied to clipboard

Q: Is it possible to use try in an exception handler?

Open torsten-liermann opened this issue 7 years ago • 1 comments

Hi,

I feel like drunk when I see the forest from lambda expressions ...

Is it possible to use Try in an exception handler? The exception handler is a technical construct that treats a given exception differently depending on the exception type. For example:

void globalIntegrationExceptionHandler(Throwable e) {
...
Try.withException(e)
  .onFail(Exception1.class, ...)
  .onFail(Exception2.class, ...)

Thanks for a hint.

torsten-liermann avatar Jul 17 '18 09:07 torsten-liermann

Hey @torsten-liermann ,

It should be possible to use Try in this way.

With later cyclops versions :

void globalIntegrationExceptionHandler(Throwable e) {
 
   Try.failure(e)
        .onFail(Exception1.class, ...)
        .onFail(Exception2.class, ...)
}

With earlier cyclops versions (e.g. for standalone cyclops-try) :

void globalIntegrationExceptionHandler(Throwable e) {
 
   Failure.of(e)
        .onFail(Exception1.class, ...)
        .onFail(Exception2.class, ...)
}

johnmcclean avatar Jul 17 '18 11:07 johnmcclean