Should API check and throw OutOfMemoryException?


More from inside the big house….  

 

Answer from the super-smart guy that wrote the GC:

 

No, you don’t need those lines. new xxx(….) will either return an
instance or throw OOM for you.


—–Original Message—–
Sent: Mon 5/12/2003
10:37 AM
Subject: Should API check and throw
OutOfMemoryException?



style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Hi, everyone,


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">My understanding is that:
OutOfMemoryException is thrown by .NET runtime when new request cannot be
satisfied. My API cannot catch this exception and continues. Instead, this
exception will manifest itself to the end user.


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Is my understanding correct? To be
clear, do we need this kind of code?


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">m_Canvas = new
MyCanvas;


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">//Do We Need The Next Three-Line
Code??


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">if (m_canvas ==
null)


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">{


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">           
Throw (new OutOfMemoryException());  


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">}


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 


style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> 

Comments (0)