forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectNotFoundException.cs
127 lines (115 loc) · 4.48 KB
/
ObjectNotFoundException.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Runtime.Serialization;
namespace NHibernate
{
/// <summary>
/// Thrown when <c>ISession.Load()</c> fails to select a row with
/// the given primary key (identifier value). This exception might not
/// be thrown when <c>Load()</c> is called, even if there was no
/// row on the database, because <c>Load()</c> returns a proxy if
/// possible. Applications should use <c>ISession.Get()</c> to test if
/// a row exists in the database.
/// </summary>
[Serializable]
public class ObjectNotFoundException : HibernateException, ISerializable
{
private object identifier;
private System.Type type;
/// <summary>
/// Initializes a new instance of the <see cref="ObjectNotFoundException"/> class.
/// </summary>
public ObjectNotFoundException( ) : base( "No object could be found with the supplied identifier." )
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ObjectNotFoundException"/> class.
/// </summary>
/// <param name="message">The message that describes the error. </param>
public ObjectNotFoundException( string message ) : base( message )
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ObjectNotFoundException"/> class.
/// </summary>
/// <param name="message">The message that describes the error. </param>
/// <param name="innerException">
/// The exception that is the cause of the current exception. If the innerException parameter
/// is not a null reference, the current exception is raised in a catch block that handles
/// the inner exception.
/// </param>
public ObjectNotFoundException( string message, Exception innerException ) : base( message, innerException )
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ObjectNotFoundException"/> class.
/// </summary>
/// <param name="message">The message that describes the error. </param>
/// <param name="identifier">The identifier of the object that was attempting to be loaded.</param>
/// <param name="type">The <see cref="System.Type"/> that NHibernate was trying to find a row for in the database.</param>
public ObjectNotFoundException( string message, object identifier, System.Type type ) : base( message )
{
this.identifier = identifier;
this.type = type;
}
/// <summary>
/// Gets the identifier of the object that was attempting to be loaded.
/// </summary>
public object Identifier
{
get { return identifier; }
}
/// <summary>
/// Gets a message that describes the current <see cref="ObjectNotFoundException"/>.
/// </summary>
/// <value>
/// The error message that explains the reason for this exception and details of
/// the object that was attempting to be loaded.
/// </value>
public override string Message
{
get { return base.Message + ": " + identifier + ", of class: " + type.FullName; }
}
/// <summary>
/// Gets the <see cref="System.Type"/> that NHibernate was trying to find a row for in the database.
/// </summary>
public System.Type Type
{
get { return type; }
}
#region ISerializable Members
/// <summary>
/// Initializes a new instance of the <see cref="ObjectNotFoundException"/> class
/// with serialized data.
/// </summary>
/// <param name="info">
/// The <see cref="SerializationInfo"/> that holds the serialized object
/// data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="StreamingContext"/> that contains contextual information about the source or destination.
/// </param>
protected ObjectNotFoundException( SerializationInfo info, StreamingContext context ) : base( info, context )
{
type = (System.Type)info.GetValue( "type", typeof(System.Type) );
identifier = info.GetValue( "identifier", typeof(object) ) ;
}
/// <summary>
/// Sets the serialization info for <see cref="ObjectNotFoundException"/> after
/// getting the info from the base Exception.
/// </summary>
/// <param name="info">
/// The <see cref="SerializationInfo"/> that holds the serialized object
/// data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="StreamingContext"/> that contains contextual information about the source or destination.
/// </param>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData( info, context );
info.AddValue( "type", type, typeof(System.Type) );
info.AddValue( "identifier", identifier, typeof(object) );
}
#endregion
}
}