Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ExceptionInfo.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Text;
5 
6 namespace SiliconStudio.Core.Diagnostics
7 {
8  /// <summary>
9  /// This class is used to store some properties of an exception. It is serializable.
10  /// </summary>
11  [DataContract]
12  public sealed class ExceptionInfo
13  {
14  /// <summary>
15  /// Initializes a new instance of the <see cref="ExceptionInfo"/> class with default values for its properties
16  /// </summary>
17  public ExceptionInfo()
18  {
19  }
20 
21  /// <summary>
22  /// Initializes a new instance of the <see cref="ExceptionInfo"/> class from an <see cref="Exception"/>.
23  /// </summary>
24  /// <param name="exception">The exception used to initialize the properties of this instance.</param>
25  public ExceptionInfo(Exception exception)
26  {
27  if (exception == null) throw new ArgumentNullException("exception");
28  Message = exception.Message;
29  StackTrace = exception.StackTrace;
30  TypeFullName = exception.GetType().FullName;
31  TypeName = exception.GetType().Name;
32  InnerException = exception.InnerException != null ? new ExceptionInfo(exception.InnerException) : null;
33  }
34 
35  /// <summary>
36  /// Gets or sets the message of the exception.
37  /// </summary>
38  public string Message { get; set; }
39 
40  /// <summary>
41  /// Gets or sets the stack trace of the exception.
42  /// </summary>
43  public string StackTrace { get; set; }
44 
45  /// <summary>
46  /// Gets or sets the full name of the exception type. Should correspond to the <see cref="Type.FullName"/> property of the exception type.
47  /// </summary>
48  public string TypeFullName { get; set; }
49 
50  /// <summary>
51  /// Gets or sets the name of the exception type. Should correspond to the <see cref="Type.Name"/> property of the exception type.
52  /// </summary>
53  public string TypeName { get; set; }
54 
55  /// <summary>
56  /// Gets or sets the <see cref="ExceptionInfo"/> of the inner exception.
57  /// </summary>
58  public ExceptionInfo InnerException { get; set; }
59 
60  /// <inheritdoc/>
61  public override string ToString()
62  {
63  var sb = new StringBuilder();
64  sb.AppendLine(Message);
65  if (StackTrace != null)
66  sb.AppendLine(StackTrace);
67  if (InnerException != null)
68  sb.AppendFormat("Inner exception: {0}{1}", InnerException, Environment.NewLine);
69  return sb.ToString();
70  }
71  }
72 }
ExceptionInfo()
Initializes a new instance of the ExceptionInfo class with default values for its properties ...
ExceptionInfo(Exception exception)
Initializes a new instance of the ExceptionInfo class from an Exception.
This class is used to store some properties of an exception. It is serializable.