Skip to content

Conversation

@svick
Copy link
Contributor

@svick svick commented Jul 13, 2018

Fixes #6446.

Changes I made:

  • Instead of using catch (Exception ex) and then testing for RuntimeWrappedException, just use catch (RuntimeWrappedException e). It's simpler and I don't see any reason not to do it this way.
  • Visual C# → C#.
  • C++/CLR → C++/CLI.
  • Improved formatting and enabled syntax highlighting.

@svick svick requested a review from BillWagner as a code owner July 13, 2018 16:18
Copy link
Contributor

@rpetrusha rpetrusha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, @svick; thanks for dramatically improving this topic. I thought that the references to WrappedException would be clearer if they're fully qualified.

- Within a `catch (Exception e)` block as a <xref:System.Runtime.CompilerServices.RuntimeWrappedException>.
- Within a `catch (RuntimeWrappedException e)` block.

By default, a Visual C# assembly catches non-CLS exceptions as wrapped exceptions. Use this method if you need access to the original exception, which can be accessed through the <xref:System.Runtime.CompilerServices.RuntimeWrappedException.WrappedException%2A> property. The procedure later in this topic explains how to catch exceptions in this manner.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to your PR: add ?displayProperty=nameWithType to <xref:System.Runtime.CompilerServices.RuntimeWrappedException.WrappedException%2A>. I think that the other two occurrences of WrappedException might be clearer with ?displayProperty=nameWithType as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpetrusha Done.

try
{
The following example shows how to catch a non-CLS exception that was thrown from a class library written in C++/CLI. Note that in this example, the C# client code knows in advance that the exception type being thrown is a <xref:System.String?displayProperty=nameWithType>. You can cast the <xref:System.Runtime.CompilerServices.RuntimeWrappedException.WrappedException%2A> property back its original type as long as that type is accessible from your code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch for C++/CLR --> C++/CLI.

Copy link
Contributor

@rpetrusha rpetrusha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the additional changes, @svick. I'll merge your PR now.

@rpetrusha rpetrusha merged commit f29e931 into dotnet:master Jul 13, 2018
@svick svick deleted the patch-5 branch July 13, 2018 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants