title: Android: How to throw an exception from Service.onCreate?
body: <p>I have a <code>Service</code> that needs do some work in it's <code>onCreate</code>, like open a file. However, if there is an <code>IOException</code>, onCreate should fail, how can I indicate this to the caller? The method doesn't throw any exceptions. I've tried using <code>stopSelf()</code>, but apparently it has no effect in before the service is created, <code>onStartCommand()</code> is still called and the code fails later because the Service is not setup correctly.</p>
  
  <pre><code>public class MyService extends Service {
    @Override
    public void onCreate() {
       try {
          // do something
       } catch (IOException ex) {
          stopSelf(); // this does nothing
          // need to show that setting up the service failed
          return;
       }         
     }
     @Override
     public int onStartCommand(Intent intent, int flags, int startId) {
        // this shouldn't be called if there was an error in onCreate
     }
  }
  </code></pre>