-
Notifications
You must be signed in to change notification settings - Fork 44
/
RollbarException.cs
110 lines (98 loc) · 4.5 KB
/
RollbarException.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
namespace Rollbar
{
using System;
using System.Runtime.Serialization;
using Rollbar.Infrastructure;
/// <summary>
/// Class RollbarException.
/// Implements the <see cref="System.Exception" />
/// </summary>
/// <seealso cref="System.Exception" />
[Serializable]
public class RollbarException
: Exception
, ISerializable
{
/// <summary>
/// The rollbar error
/// </summary>
private readonly InternalRollbarError _rollbarError;
/// <summary>
/// Initializes a new instance of the <see cref="RollbarException" /> class.
/// </summary>
internal RollbarException()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RollbarException" /> class.
/// </summary>
/// <param name="rollbarError">The rollbar error.</param>
internal RollbarException(InternalRollbarError rollbarError)
: this(rollbarError, rollbarError.ToString())
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RollbarException"/> class.
/// </summary>
/// <param name="rollbarError">The rollbar error.</param>
/// <param name="innerException">The inner exception.</param>
internal RollbarException(InternalRollbarError rollbarError, Exception? innerException)
: this(rollbarError, rollbarError.ToString(), innerException)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RollbarException"/> class.
/// </summary>
/// <param name="rollbarError">The rollbar error.</param>
/// <param name="message">The message.</param>
internal RollbarException(InternalRollbarError rollbarError, string? message)
: base(!string.IsNullOrWhiteSpace(message) ? message : rollbarError.ToString())
{
this._rollbarError = rollbarError;
}
/// <summary>
/// Initializes a new instance of the <see cref="RollbarException" /> class.
/// </summary>
/// <param name="rollbarError">The rollbar error.</param>
/// <param name="message">The message.</param>
/// <param name="innerException">The inner exception.</param>
internal RollbarException(InternalRollbarError rollbarError, string? message, Exception? innerException)
: base(!string.IsNullOrWhiteSpace(message) ? message : rollbarError.ToString(), innerException)
{
this._rollbarError = rollbarError;
}
/// <summary>
/// Initializes a new instance of the <see cref="RollbarException" /> class.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"></see> that contains contextual information about the source or destination.</param>
protected RollbarException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
this._rollbarError =
(InternalRollbarError) (info.GetValue(nameof(this._rollbarError), typeof(InternalRollbarError)) ?? InternalRollbarError.GeneralError);
}
/// <summary>
/// Gets the rollbar error.
/// </summary>
/// <value>The rollbar error.</value>
public InternalRollbarError RollbarError
{
get { return this._rollbarError; }
}
/// <summary>
/// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo">SerializationInfo</see> with information about the exception.
/// </summary>
/// <param name="info">
/// The <see cref="T:System.Runtime.Serialization.SerializationInfo">SerializationInfo</see> that holds the serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="T:System.Runtime.Serialization.StreamingContext">StreamingContext</see> that contains contextual information about the source or destination.
/// </param>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue(nameof(this._rollbarError), this._rollbarError);
}
}
}