I have a custom class with constructor, the class is setup such that it would legitly fail to init in some conditions. How do I return nothing?
Share
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.
You can’t return anything from a constructor, it’s there to initialize.
There are a couple of things you could do, depending on the situation:
If the failiure to initialize is an exceptional circumstance, throw an exception and catch it using a
Tryblock:If it fails a lot and you can’t filter input or anything, make the constructor
Privateand construct in aSharedmethod: