java解析xml之jdom解析xml示例分享。本站提示廣大學習愛好者:(java解析xml之jdom解析xml示例分享)文章只能為提供參考,不一定能成為您想要的結果。以下是java解析xml之jdom解析xml示例分享正文
一個迭代開辟中的網站不免存在bug,出bug的時刻客戶體驗就很欠好了,為處理此成績,可以在class error發生的時刻,觸發跳轉到同一提醒頁面,並給開辟人員發郵件報毛病信息,進步測試才能和用戶體驗。以下是焦點辦法;在ApplicationController中添加以下代碼,分歧rails版本的class error略有變更。
AR_ERROR_CLASSES = [ActiveRecord::RecordNotFound, ActiveRecord::StatementInvalid]
ERROR_CLASSES = [NameError, NoMethodError, RuntimeError,
ActionView::TemplateError,
ActiveRecord::StaleObjectError, ActionController::RoutingError,
ActionController::UnknownController, AbstractController::ActionNotFound,
ActionController::MethodNotAllowed, ActionController::InvalidAuthenticityToken]
ACCESS_DENIED_CLASSES = [CanCan::AccessDenied]
if Rails.env.production?
rescue_from *AR_ERROR_CLASSES, :with => :render_ar_error
rescue_from *ERROR_CLASSES, :with => :render_error
rescue_from *ACCESS_DENIED_CLASSES, :with => :render_access_denied
end
#called by last route matching unmatched routes. Raises RoutingError which will be rescued from in the same way as other exceptions.
#備注rails3.1後ActionController::RoutingError在routes.rb中最初加以下代碼能力catch了。
#rails3下:match '*unmatched_route', :to => 'application#raise_not_found!'
#rails4下:get '*unmatched_route', :to => 'application#raise_not_found!'
def raise_not_found!
raise ActionController::RoutingError.new("No route matches #{params[:unmatched_route]}")
end
def render_ar_error(exception)
case exception
when *AR_ERROR_CLASSES then exception_class = exception.class.to_s
else exception_class = 'Exception'
end
send_error_email(exception, exception_class)
end
def render_error(exception)
case exception
when *ERROR_CLASSES then exception_class = exception.class.to_s
else exception_class = 'Exception'
end
send_error_email(exception, exception_class)
end
def render_access_denied(exception)
case exception
when *ACCESS_DENIED_CLASSES then exception_class = exception.class.to_s
else exception_class = "Exception"
end
send_error_email(exception, exception_class)
end