Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should be passed as the objectName when throwing an ObjectDisposedException?

When implementing IDisposable, I undertand that every method that shouldn't be called after the object's been disposed should throw the ObjectDisposedException. But what is the standard for the name object that should be passed to the exception's constructor?

like image 697
Wilhelm Avatar asked Dec 26 '09 22:12

Wilhelm


1 Answers

I believe the recommended practice is to throw the following:

throw new ObjectDisposedException(GetType().FullName); 

Or including the check, these two lines of code at the top of each method that needs it (obviously not the Dispose method itself):

if (this.disposed)     throw new ObjectDisposedException(GetType().FullName); 

Might even be helpful to refactor this into a tiny method for usability.

like image 190
Noldorin Avatar answered Sep 30 '22 05:09

Noldorin