class Sinatra::Base

def dispatch!

Dispatch a request with error handling.
def dispatch!
  @params = indifferent_params(@request.params)
  force_encoding(@params)
  invoke do
    static! if settings.static? && (request.get? || request.head?)
    filter! :before
    route!
  end
rescue ::Exception => boom
  invoke { handle_exception!(boom) }
ensure
  begin
    filter! :after unless env['sinatra.static_file']
  rescue ::Exception => boom
    invoke { handle_exception!(boom) } unless @env['sinatra.error']
  end
end