Trivia: How does CLR create an OutOfMemoryException
When the system goes out of memory a OutOfMemoryException is thrown. Similarly for stack overflow a StackOverFlorException is thrown. Now typically an exception is thrown as follows (or the corresponding native way)
throw new System.OutOfMemoryException();
But when the system is already out of memory there's a little chance that creating an exception object will succeed. So how does the CLR create these exception objects?
The answer is trivial and as expect, at the very application start it creates all these exception objects and stores them in a static list. In case these exceptions are to be thrown then it is fetched from this list and thrown.
The consequence of handling Stack overflow is even bigger because once the stack has overflown calling even a single method in that thread is equally dangerous and can cause further corruption. That is the material for another post :)
Comments
Anonymous
April 29, 2008
PingBack from http://microsoftnews.askpcdoc.com/tech/trivia-how-does-clr-create-an-outofmemoryexceptionAnonymous
April 29, 2008
Does that mean all Exception classes in System namespace is mainted or only the Offerflow ones??? Pretty interestingAnonymous
April 29, 2008
Not all but only the ones that can have problems being created later.Anonymous
May 08, 2008
same is true for StackOverflowException.