Mono Class Library: System.ObjectDisposedException Overview | MembersSystem.ObjectDisposedException Constructor |
Constructs and initializes a new instance of the ObjectDisposedException class. [Edit]
|
- objectName
- A string containing the name of the disposed object. [Edit]
- message
- A string that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. [Edit]
- message
- Documentation for this section has not yet been entered. [Edit]
This constructor initializes the ObjectDisposedException.Message property of the new instance using message, and the ObjectDisposedException.ObjectName property using objectName . If message is null, the ObjectDisposedException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.
The ObjectDisposedException.InnerException property of the new instance is initialized to null.
[Edit]
The following example throws a ObjectDisposedException instance created using this constructor.
C# Example using System; public class ExampleDisposableObject : IDisposable { public static void Main() { ExampleDisposableObject obj = new ExampleDisposableObject(); obj.Close(); try { Console.WriteLine(obj); } catch (ObjectDisposedException e) { Console.WriteLine("Caught: {0}", e.Message); } } public ExampleDisposableObject() { isDisposed = false; } ~ExampleDisposableObject() { Dispose(true); } public void Close() { Dispose(true); } public void Dispose() { Dispose(true); } public void Dispose(bool disposing) { isDisposed = true; } public override String ToString() { if(isDisposed) { string message = "Oh-oh! This object has been disposed!"; string objectName = "ExampleDisposableObject"; throw new ObjectDisposedException(objectName, message); } else return "Hello, World!"; } private bool isDisposed; }The output is
Caught: Oh-oh! This object has been disposed!
Object name: "ExampleDisposableObject".
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0