How should I handle exceptions in my Dispose() method?
问题 I'd like to provide a class to manage creation and subsequent deletion of a temporary directory. Ideally, I'd like it to be usable in a using block to ensure that the directory gets deleted again regardless of how we leave the block: static void DoSomethingThatNeedsATemporaryDirectory() { using (var tempDir = new TemporaryDirectory()) { // Use the directory here... File.WriteAllText(Path.Combine(tempDir.Path, "example.txt"), "foo\nbar\nbaz\n"); // ... if (SomeCondition) { return; } if