-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an internal ObjectNotDisposedException (#18605)
that we can throw/immediately catch from finalizers when an object wasn't properly disposed and there's pending work being lost or resources being leaked
- Loading branch information
Showing
6 changed files
with
84 additions
and
20 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
sdk/core/Azure.Core/src/Shared/ObjectNotDisposedException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
|
||
namespace Azure.Core | ||
{ | ||
/// <summary> | ||
/// An exception thrown and immediately caught by finalizers with pending | ||
/// work or resources that were not properly disposed. This exception only | ||
/// exists to notify users of incorrect usage while debugging with first | ||
/// chance exceptions. | ||
/// </summary> | ||
internal class ObjectNotDisposedException : InvalidOperationException | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of an ObjectNotDisposedException. | ||
/// </summary> | ||
/// <param name="message">The exception message.</param> | ||
public ObjectNotDisposedException(string message) : base(message) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
sdk/core/Azure.Core/tests/ObjectNotDisposedExceptionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.Core.Tests | ||
{ | ||
public class ObjectNotDisposedExceptionTests | ||
{ | ||
[Test] | ||
public void Construct() | ||
{ | ||
string message = "Work was not cleaned up."; | ||
var ex = new ObjectNotDisposedException(message); | ||
Assert.AreEqual(message, ex.Message); | ||
} | ||
|
||
[Test] | ||
public void IsInvalidOperationException() | ||
{ | ||
var ex = new ObjectNotDisposedException("Work was not cleaned up."); | ||
Assert.True(ex is InvalidOperationException); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters