/
XunitException.cs
71 lines (64 loc) · 1.7 KB
/
XunitException.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#if XUNIT_NULLABLE
#nullable enable
#else
// In case this is source-imported with global nullable enabled but no XUNIT_NULLABLE
#pragma warning disable CS8625
#endif
using System;
namespace Xunit.Sdk
{
/// <summary>
/// The base assert exception class. It marks itself with <see cref="IAssertionException"/> which is how
/// the framework differentiates between assertion fails and general exceptions.
/// </summary>
#if XUNIT_VISIBILITY_INTERNAL
internal
#else
public
#endif
partial class XunitException : Exception, IAssertionException
{
/// <summary>
/// Initializes a new instance of the <see cref="XunitException"/> class.
/// </summary>
/// <param name="userMessage">The user message to be displayed</param>
public XunitException(
#if XUNIT_NULLABLE
string? userMessage) :
#else
string userMessage) :
#endif
this(userMessage, null)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="XunitException"/> class.
/// </summary>
/// <param name="userMessage">The user message to be displayed</param>
/// <param name="innerException">The inner exception</param>
public XunitException(
#if XUNIT_NULLABLE
string? userMessage,
Exception? innerException) :
#else
string userMessage,
Exception innerException) :
#endif
base(userMessage, innerException)
{ }
/// <inheritdoc/>
public override string ToString()
{
var className = GetType().ToString();
var message = Message;
string result;
if (message == null || message.Length <= 0)
result = className;
else
result = $"{className}: {message}";
var stackTrace = StackTrace;
if (stackTrace != null)
result = $"{result}{Environment.NewLine}{stackTrace}";
return result;
}
}
}