<!-- GENERATED FILE - DO NOT EDIT This file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets). Source File: /docs/mdsource/members-throw.source.md To change this file edit the source file and then run MarkdownSnippets. --> # Members that throw Members that throw exceptions can be excluded from serialization based on the exception type or properties. By default members that throw `NotImplementedException` or `NotSupportedException` are ignored. Note that this is global for all members on all types. Ignore by exception type: <!-- snippet: IgnoreMembersThatThrow --> <a id='snippet-IgnoreMembersThatThrow'></a> ```cs [Fact] public Task CustomExceptionProp() { var target = new WithCustomException(); var settings = new VerifySettings(); settings.IgnoreMembersThatThrow<CustomException>(); return Verify(target, settings); } [Fact] public Task CustomExceptionPropFluent() { var target = new WithCustomException(); return Verify(target) .IgnoreMembersThatThrow<CustomException>(); } ``` <sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3742-L3761' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMembersThatThrow' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> Or globally: <!-- snippet: IgnoreMembersThatThrowGlobal --> <a id='snippet-IgnoreMembersThatThrowGlobal'></a> ```cs VerifierSettings.IgnoreMembersThatThrow<CustomException>(); ``` <sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L3736-L3740' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMembersThatThrowGlobal' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> Result: <!-- snippet: SerializationTests.CustomExceptionProp.verified.txt --> <a id='snippet-SerializationTests.CustomExceptionProp.verified.txt'></a> ```txt {} ``` <sup><a href='/src/Verify.Tests/Serialization/SerializationTests.CustomExceptionProp.verified.txt#L1-L1' title='Snippet source file'>snippet source</a> | <a href='#snippet-SerializationTests.CustomExceptionProp.verified.txt' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> Ignore by exception type and expression: <!-- snippet: IgnoreMembersThatThrowExpression --> <a id='snippet-IgnoreMembersThatThrowExpression'></a> ```cs [Fact] public Task ExceptionMessageProp() { var target = new WithExceptionIgnoreMessage(); var settings = new VerifySettings(); settings.IgnoreMembersThatThrow<Exception>(_ => _.Message == "Ignore"); return Verify(target, settings); } [Fact] public Task ExceptionMessagePropFluent() { var target = new WithExceptionIgnoreMessage(); return Verify(target) .IgnoreMembersThatThrow<Exception>(_ => _.Message == "Ignore"); } ``` <sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2408-L2429' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMembersThatThrowExpression' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> Or globally: <!-- snippet: IgnoreMembersThatThrowExpressionGlobal --> <a id='snippet-IgnoreMembersThatThrowExpressionGlobal'></a> ```cs VerifierSettings.IgnoreMembersThatThrow<Exception>(_ => _.Message == "Ignore"); ``` <sup><a href='/src/Verify.Tests/Serialization/SerializationTests.cs#L2401-L2405' title='Snippet source file'>snippet source</a> | <a href='#snippet-IgnoreMembersThatThrowExpressionGlobal' title='Start of snippet'>anchor</a></sup> <!-- endSnippet --> Result: <!-- snippet: SerializationTests.ExceptionMessageProp.verified.txt --> <a id='snippet-SerializationTests.ExceptionMessageProp.verified.txt'></a> ```txt {} ``` <sup><a href='/src/Verify.Tests/Serialization/SerializationTests.ExceptionMessageProp.verified.txt#L1-L1' title='Snippet source file'>snippet source</a> | <a href='#snippet-SerializationTests.ExceptionMessageProp.verified.txt' title='Start of snippet'>anchor</a></sup> <!-- endSnippet -->