Consider the following code (ASP.NET/C#):
private void Application_Start(object sender, EventArgs e) { if (!SetupHelper.SetUp()) { throw new ShitHitFanException(); } }
I was never too indecisive to simply collapse my own exception type, mainly because I found (bad practice or not) that basically a reasonable descriptive type name gives us enough so that developers can go through to find out what happened and why something could happen. Sometimes existing .NET exception types even address these needs - regardless of the message.
In this particular scenario, for demonstration purposes only, the application must die from a terrible, shameful death if SetUp not executed properly (according to its return value), but I cannot find an existing exception type in .NET that seems to be will be sufficient; although, I'm sure he will be there, and I just donโt know about it.
Brad Abrams published this article listing some of the available exception types . I say a few because the article has been since 2005, and although I try to keep abreast of the latest developments, this is more than a plausible assumption that more versions are added to future versions of the frameworks that I still donโt know.
Of course, Visual Studio gives you a well-formatted, scrollable list of exceptions through Intellisense, but even with the analysis, I cannot find anything that would seem to be sufficient for this situation ...
ApplicationException: ... when a non-fatal application error
The name seems reasonable, but the error is very definitely fatal - the application is dead.
ExecutionEngineException: ... when there is an internal error in the CLR execution engine
Again, it sounds reasonable, superficial; but this is a very definite goal and to help me here, of course, is not so.
HttpApplicationException: ... when there is an error processing the HTTP request
Well, we run the ASP.NET expression! But we are also just pulling a straw here.
InvalidOperationException: ... when the call is not valid for the current state of the instance
This is wrong, but I add it to the list of "maybe you should put a gun in your head, yes."
OperationCanceledException: ... after canceling the operation, the thread ran
Maybe I donโt feel so bad using this one, but I will still hijack a hell of a lot.
You may even ask why on earth I would like to make an exception here, but the idea is to find out that if I did this , then you know about the corresponding exception for such a scenario? And basically, to what extent can we correspond with .NET in a rational way?