How to handle error if application loading fails in play framework

Referring to documentation (, I have created my own application loader by extending ApplicationLoader

import play.api._
import play.api.ApplicationLoader.Context
import play.api.routing.Router
import play.filters.HttpFiltersComponents

    class MyApplicationLoader extends ApplicationLoader {
      def load(context: Context) = {
        new MyComponents(context).application
    class MyComponents(context: Context) extends BuiltInComponentsFromContext(context) with HttpFiltersComponents with MyDatabaseComponents{
      lazy val router = Router.empty

In my case, the MyDatabaseComponents could fail if the database service isn’t running at the time the application starts. How can I gracefully handle this error and stop the application from loading? Ideally, I’ll like to show a web page or send a REST response that the application isn’t available.