-
Notifications
You must be signed in to change notification settings - Fork 809
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
RuntimeWrappedException cannot be caught #18374
Comments
There are two options how I see this being addressed:
I think the first option is the safest one. It is a potential breaking change if people rely on |
To assess the impact, is there a library/framework/other_compiler making use of non-Exception throws practically? I would not change the codegen, but |
Another way of addressing this would be a compiler-intrinsic active pattern binding a plain |
@T-Gro I am not aware of a concrete case where this would happen. I can see interop with C++/CLI running into the possibility, but non-CLS exceptions are seldom used in other situations. It is just something I like to check out of curiosity. 😉 Also both C# and VB.NET emit I like the idea of a compiler-intrinsic active pattern though, but it could work with let (|RuntimeWrappedException|_|)(x : Exception) =
match x with
| :? RuntimeWrappedException as wrapped -> Some (wrapped.WrappedException)
| _ -> None There is a slight difference in doing it that way compared to the intrinsic due to the fact that you can actually construct a |
When a non-
Exception
object is thrown (from CIL or other languages that support it), it cannot be caught in F# by default.Repro steps
Expected behavior
The exception should be caught either as
System.String
orSystem.Runtime.CompilerServices.RuntimeWrappedException
.Actual behavior
This is caused by the generated exception handler:
F# here catches everything, but the cast to
Exception
throws another exception since the object is not anException
.Known workarounds
The code above succeeds if the attribute that controls how wrapped exceptions are exposed is used explicitly:
Related information
Throwing a
RuntimeWrappedException
manually does not exhibit this behaviour because the runtime does not treat it as a special case then and does not unwrap the value.Environment: https://sharplab.io/#v2:DYLgZgzgNALiCWwA+wCmMAEMAWAnA9gO74BGAVhgBQAeIpZAlBgLxUDEGARDgYZxtQxsGAWABQ4mLgCe4jFjxF6XGKggxO4wvBzikGVBgC0APgwAHXPAB2MMFwCkAeX6ogA=
The text was updated successfully, but these errors were encountered: