Type constraint mismatch when reraising a caught exception in a task CE #14482
-
I have some code somewhat like the following: (actual types obfuscated) // unit -> Task<MyClass option>
member this.DoThing ()=
task {
try
let! result = something.doAsync ()
return result // I know, this could've just been return!, please overlook
with
| ex ->
logger.LogError(ex, "Error doing the thing")
raise ex // I know this doesn't preserve the stack trace, please overlook
return None // Won't compile without this line
} I am very confused by the compile-time behavior of this. Why must the
I found the docs that say |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
All you should have to do here is |
Beta Was this translation helpful? Give feedback.
All you should have to do here is
return
theraise ex
expression.raise
(likethrow
,failwith
and others), returns a generic type so that it can be used in situations like this, you just always have toreturn
something out of a CE context.