Alex Rivera | Logout

When is it reasonable to check if this object has been disposed and throw ObjectDisposedException?

Asked 2011-05-27T09:38:06.907
10

In a class that implements IDisposable, when is it reasonable to check if the object has been disposed and throw ObjectDisposedException if it has? In all public methods and properties (except Dispose)? Sometimes? Never?

Edit
Report

1 Answer

5

You should implement that check only in methods that don't work on a disposed object.

For example:
If your class closes the database connections or file handles in Dispose, all methods that need those database connections or file handles need to check if the instance is already exposed.

answered 2011-05-27T09:44:01.807

Your Answer