I know the general matter has been discussed in this stackoverflow topic already (constructors never return null), but considering its significance in this concrete matter, I would like to know if the official Android documentation of the SoundPool constructor is wrong then:
Constructor. Returns
a SoundPool object, or null if creation failed
I’m asking this because we’re talking about no less than the official documentation of Android that has been up for years (in case of SoundPool).
Checking the Android source code, the SoundPool throws a RuntimeException in case of an error in constructor. (The pre-2.3 Android did not even throw an exception.) Perhaps the documentation tries to express that if the exception is caught, then the variable where I intended to store the object reference remains null? In this case, the doc is still very poorly worded. Am I missing something?
EDIT: considering this might not be a very content-rich question (even though it may be useful — see my comments), a simple Yes or No would be sufficient, and then the thread can get closed. I want to make sure I haven’t overlooked anything.
SoundPoolmay throw an exception in it’s constructor. You can ignore it. They specifically chose to throw aRuntimeException(on 2.3+) as opposed to a checked exception which indicates the API designers consider this a good enough reason to crash an app and that does not need to be routinely handled.So no, it can’t return null. But if you handle the exception then yes, your reference to the object will be
nullbecause the constructor did not complete.