-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try.withCatch #256
Comments
Hey @jainh, this is the expected behaviour by default, although Try can be configured to catch subsequent exceptions in map / flatMap. You can use Try.of(value,Exceptions..) to configure Try such that it will capture any Exceptions thrown in subsequent methods. The reason we don't do this be default is because it may hide errors in code and we felt it important that engineers make a conscious / deliberate decision to use it. Your example
Could become
We see Try primarily as a data type that represents either an error or a successful value, rather than being primarily a trapper of exceptions (although it can be used for that purpose). An alternative to turning on full exception catching, is to use flatMap with a nested Try.withCatch
|
@johnmcclean-aol
But |
Hmmm.. That seems strange. Try.withCatch takes a CheckedSupplier so it should compile. What version are you using? This compiles for me (tested against cyclops-react 2.0.0-MI4)
If you are using cyclops-react (rather than cyclops-try) you could also use ExceptionSoftener.softenSupplier to soften the ParseException (but you shouldn't have too). |
I think this could IDE intellij i am using but let me run it then i will update you. |
@johnmcclean-aol do you how to apply parallel operation on result return after successful flatmap operation and then collect them ? |
Please do. I think that version should compile also (as it is also using CheckedSupplier to handle Checked Exceptions e.g. https://github.com/aol/cyclops/blob/v7.2.0/cyclops-try/src/main/java/com/aol/cyclops/trycatch/Try.java#L224) |
@jainh Do you want to process a the result in parallel in some way? i.e. is it a Collection that you would convert to a Stream and execute in parallel? I can show an example of that below
|
but value in map v is expected to be JSONObject but it shows R. |
@johnmcclean-aol
Does that look ok to you? just sanity check |
When i want to try like as follows
Try.witchCatch(()->a()).onFail().map(()->b())..
where b() throws an exception as well, it says b with unhandled exception, who do deal in such situation? we can not call from map or flatmap function that throws an exception?
The text was updated successfully, but these errors were encountered: