- Does using operator new in c# might fail (if it requires a large memory for example)? -Solved-
- And how to discover it? -Solved-
- What other failures new operator might throw?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A
newoperator that invokes a constructor can throw any exception that you can imagine. Fro example, if inside the constructor it tries to allocate something big and fails, then that exception might be caught and re-raised as something more exotic.Of course, at the point when you start seeing out-of-memory you should probably consider the process terminally ill, and put it out of its misery ASAP.
Constructors can also, despite all the rumours to the contrary, return
nulleven for classes – but that is an extreme edge-case, bordering on the pathological.