Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Why we should not implement IDisposable when building a custom exception class?
Posted
Updated 28-Sep-17 10:47am

1. IDisposable interface provides a mechanism for releasing unmanaged resources, so it should be used only if you use them like: file streams, database connections, sockets, memory allocation, etc. See details in MSDN[^]

2.In the case of custom exception you should fallow the rules described here:
http://msdn.microsoft.com/en-us/library/vstudio/ms229064(v=vs.100).aspx[^]
 
Share this answer
 
v2
Because you are going to throw the exception and there won't be anyone then to dispose of it. Exception handlers are often generic based on the base exception class and won't be ready to handle a disposable resource.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900