by ignoramous · 11y ago · 0 comments
Like in Java:
try {
print(awesomeObj.getSomeState());
} catch(NullPointerException npe) {
awesomeObj = AwesomeObj.getInstance();
}
would be considered very bad. You would instead be expected to do: if (awesomeObj == null) awesomeObj = AwesomeObj.getInstance();
print(awesomeObj.getSomeState());
(how do you <code-wrap> stuff on here?)It's not what I would have done.
(Mark text as code by putting it on a fresh line with two or more spaces in front. I don't think there is a way to do this inline.)
Exceptions are, pretty much explicitly, a control flow mechanism. That's what they do, they transfer control from one place to another. It's like people are getting hung up on the name.