You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
There are two options how I see this being addressed:
Apply RuntimeCompatibilityAttribute implicitly. This makes it behave exactly like C# in this situation.
Change castclass to isinst. It is however unclear how the exception should be exposed/caught in that case, since the language applies the catch patterns on the Exception type, not obj.
I think the first option is the safest one. It is a potential breaking change if people rely on try-with throwing an InvalidCastException in this case, but I don't think that is the supposed behaviour.
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: