question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to try an alternative for failed Try with a new call that returns a Try

See original GitHub issue

So what i’m looking for is something like what other frameworks (jvm) calls

public Try<T> OrElseTry(this Try<T>, Func<T> alternative)

So if the this Try is in Error then alternative is called Is that possible? It seems resonable.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mathiasbncommented, Sep 21, 2017

Thank you for quick reply. I can live with that extension. I feared that I missed something, I’m not used to frameworks so Haskell’ish near.

0reactions
louthycommented, Feb 7, 2018

@mathiasbn Hi Mathias, a bit late, but this is fixed in v2.2.7-beta

There is now a choice function in the Prelude for Try, TryOption, TryAsync, TryOptionAsync, and Task.

For example:

var ma = Try<int>(() => throw new Exception());
var mb = Try<int>(() => throw new Exception());
var mc = Try(() => 123);

var res = choice(ma, mb, mc);

Assert.True(res.IfFail(0) == 123);

Plus is available for chaining OR operations.

var res = ma.Plus(mb.Plus(mc));

Obviously that’s not quite as elegant as the choice approach.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should try-catch blocks be used when calling functions that ...
There's an alternative to exceptions using a return value that may represent an error but I'm going to ignore that option in this...
Read more >
try / else with return in try block - python
When you call divide(1, 1) , the try clause runs successfully, and returns. So the else clause is never reached. Why does the...
Read more >
How to handle errors with grace: failing silently is not an ...
Catch early, catch often. Catch your exceptions as close to the source at the lowest level possible. Maintain consistency and hide the details...
Read more >
The try-with-resources Statement - Exceptions
This Java tutorial describes exceptions, basic input/output, concurrency, regular expressions, and the platform environment.
Read more >
Error Handling in Go that Every Beginner should Know
There are two common methods for handling errors in Go — Multiple return values and panic. Error Handling using Multiple Return Values. We...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found