To throw exceptions, I usually use built-in exception classes, e.g. ArgumentNullException
and NotSupportedException
. However, sometimes I need to use a custom exception and in that case I write:
class SlippedOnABananaException : Exception { }
class ChokedOnAnAppleException : Exception { }
and so on. Then I throw and catch these in my code. But today I came across the ApplicationException
class - should I be using that instead? What's it for?
It does seem inefficient to have lots of effectively identical Exception classes with different names (I don't usually need any individual functionality). But I dislike the idea of catching a generic ApplicationException
and having to use extra code to determine what the error was.
Where should ApplicationException
fit in with my code?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…