I apologize for the trivial nature of the following question, but I couldn't find an answer after a few minutes of Google searching.
I have a Java object that acts as the front-end to a developer SDK. This object is called DataCollectionManager
. Like most, if not all, Android Manager objects (CameraManager, LocationManager, etc.), the DataCollectionManager
manages the connection to a service running on the device.
When a client using the SDK creates a DataCollectionManager
object, the constructor will bind to the DataCollectionService
running on the device. The client provides a listener interface to the constructor that will be called back when the service connection has been established. Once this listener has been notified, the client knows it's okay to make API calls on the DataCollectionManager
.
However, it is possible that a client will attempt to make an API call prior to the establishment of the service connection. In this case, I've got a block of code that looks like this at the top of each method:
if (!mServiceBound) {
// do something
}
I'd like to throw an exception if the service is not bound, but I'm not sure which one.
Which exception should I throw? I'd like to throw a checked exception so the client code doesn't crash. Is there a preexisting exception that fits well in this case, or should I just define my own?