Hey everyone. I have a function that looks like t...
# announcements
m
Hey everyone. I have a function that looks like this:
Copy code
fun getMyResult(): Result<TheThing>{
    var myResult = Result.success(TheThing())
    return myRresult.mapCatching {
           throw IllegalArgumentException("")
    }
}
My expectation here is that the
getMyResult()
function will return a Failure Result that wraps the IllegalArgumentException. However, what is happening is that my application just crashes. Am I misunderstanding how
mapCatching
works?
m
In theory yes, but how is it crashing? With that IllegalArgumentException or other?
d
maybe could be the typo on
return myRresult..
? 🤔
m
@Daniele Andreoli i simplified my function here and typed it in so no typo in the actual method 🙂
@Matteo Mirk yeah the crash is happening at the IllegalArgumentException
e
Do you have a self-contained reproducer? Does not repeat for me: https://pl.kotl.in/TkAFX7Drc
m
@elizarov I tried to reproduce in the playground you posted but can’t seem to repro it. https://pl.kotl.in/atQcSt6Or The more accurate representation, as shown in my link, is that it’s a suspend function that contains the
mapCatching
though i’m not sure if that should change anything
image.png
This is the exact stack trace in my project that I get, with the line number pointing directly at the
mapCatching
I found the issue to my problem and it’s pretty silly. it was crashing because I was calling
getOrThrow
at one of the call sites for this particular function 🤦‍♂️ . What’s bizarre though is that the logs point me to
mapCatching
instead of the
getOrThrow
location