def safely(&block)
begin
block.call
rescue
report_method = $stderr.respond_to?(:err) ? :err : :puts
Deltacloud::ExceptionHandler::exceptions.each do |exdef|
if exdef.match?($!)
new_exception = exdef.handler($!)
m = (new_exception && !new_exception.message.nil?) ? new_exception.message : $!.message
unless ENV['RACK_ENV'] == 'test'
$stderr.send(report_method, "#{[$!.class.to_s, m].join(':')}\n#{$!.backtrace[0..10].join("\n")}")
end
raise exdef.handler($!) unless new_exception.nil?
end
end
$stderr.send(report_method, "[NO HANDLED] #{[$!.class.to_s, $!.message].join(': ')}\n#{$!.backtrace.join("\n")}")
raise Deltacloud::ExceptionHandler::BackendError.new($!, "Unhandled exception or status code (#{$!.message})")
end
end