-
Notifications
You must be signed in to change notification settings - Fork 859
RuntimeWrappedException cannot be caught #18374
Copy link
Copy link
Open
Labels
Area-Compiler-CodeGenIlxGen, ilwrite and things at the backendIlxGen, ilwrite and things at the backendBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.(Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone
Metadata
Metadata
Assignees
Labels
Area-Compiler-CodeGenIlxGen, ilwrite and things at the backendIlxGen, ilwrite and things at the backendBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.(Internal MS Team use only) Describes an issue with limited impact on existing code.
Type
Fields
Give feedbackNo fields configured for Bug.
Projects
Status
New
When a non-
Exceptionobject 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.StringorSystem.Runtime.CompilerServices.RuntimeWrappedException.Actual behavior
This is caused by the generated exception handler:
.try { ldstr "test" throw // ... } catch [netstandard]System.Object { castclass [System.Runtime]System.Exception // InvalidCastException stloc.0 // ... }F# here catches everything, but the cast to
Exceptionthrows 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
RuntimeWrappedExceptionmanually 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=