问题标签 [exceptionhandler]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
2063 浏览

java - 使用 @ControllerAdvice 注释类处理异常时丢失堆栈跟踪

我有一个弹簧 REST 应用程序。我从控制器中抛出所有异常并在一个共同的地方处理它们,一个名为 ExceptionHandlerControllerAdvice 的类,使用@ControllerAdvice 进行注释。我有多个用@ExceptionHandler 注释的方法来处理每种类型的异常。在这些方法中,我发送自定义错误 json 响应。在将此错误 json 发送给消费者之前,我在日志中记录了异常的堆栈跟踪。见代码-

问题是我丢失了实际的堆栈跟踪,它告诉我异常的确切来源。有人熟悉这个问题吗?
[编辑]查看日志。

0 投票
0 回答
379 浏览

php - 如何使我的“失败的请求”出现在 Application Insights 图表和分析中?

如何使我的“失败的请求”出现在 Application Insights 图表和分析中?

微软天青 | 应用程序洞察打印 1

微软天青 | 应用程序洞察打印 2

我在WordPress中有一个带有multisite的网站,在Microsoft Azure的服务器内,并使用插件Application Insights

github:微软/ApplicationInsights-WordPress/

github:微软/ApplicationInsights-WordPress/pull/5/files

我试图添加echo以检查是否正在调用两个“函数”之一,但我没有收到任何返回。

我是一名编程学生,所以我对如何调试代码知之甚少,我总是以失败告终并收到错误 500。如果你能帮助我,我非常感谢你!

0 投票
0 回答
354 浏览

java - 使用 @ControllerAdvice 和 @ExceptionHandler 时的 finally 块处理

情况

我有一个控制器类,在控制器类中尝试捕获异常处理。最近我一直在尝试将传统的 try catch 块移到 spring 的 @ControllerAdvice 和 @ExceptionHandler 中。

但是我的控制器有一个 finally 块。所以我一直在寻找如何在使用 @ControllerAdvice 和 @ExceptionHandler 方法时处理 finally 块。我找不到任何解决方案来处理这种情况。

任何帮助表示赞赏。

0 投票
0 回答
107 浏览

spring - How spring mvc handle responsebody and view excpetion?

I have a controller as

Is it possible to create ControllerAdvice(s) to handle the controller method as different result without moving these to message to different classes. I mean: 1. test1 returns a String message: if there is exception, handle it with handleError1 and return a message. 2. test1 returns a view : if there is exception, handle it with handleError2 and return/redirect to a view.

if use @ControllerAdvice(annotations=RestController.class) @ControllerAdvice(annotations=Controller.class)

We need to create more controllers.

0 投票
1 回答
435 浏览

java - Questions about the size of the Springboot upload file

An error occurs when I upload the file size bigger than the set value. I want to catch this exception and return it to the browser.The e.getCause().getMessage() has a value , but not successfully return to browser. Normally, a piece of json will be displayed on the browser. handleFileFormatException is no problem, but handleIllegalStateException can't display any message and occurs "Unable to access this site" on the browser.The paths are all shown:localhost:8080. These two methods are almost the same, the difference is that FileFormatExceptio is my defined exception class, but IllegalStateException is not. Why didn't it return json entity to the browser. I don't know what to do.Who can help me? Thank you!

application.properties: application.properties

@ExceptionHandler @ExceptionHandler

ExceptionResponse

}

Console warning, NO error

Browser press F12 enter image description here

enter image description here

Controller

getStatus

0 投票
1 回答
230 浏览

android - Android - 将错误记录到电子邮件帐户

我已经在我的应用程序中实现了一个 ErrorHandler 类,它工作得很好,但我不确定我所做的是否适合“最佳实践”,只是想与你分享它以获得你的意见。

我的问题很傻,我的课很简单。我要做的就是下一个:在我的整个 java 代码的每个 catch 块中,我调用 ErrorHabdler.log(e) (它作为 AsyncTask 工作)并且当我使用 AWS 时 log(e) 的作用是捕获有关错误的所有信息,例如消息、设备名称和型号等(无用户信息),并将带有错误的格式化电子邮件发送到特定的电子邮件地址。

另一种可能性是在我的 AWS DynamoDB 集中创建一个名为 Exceptions 的新表,而不是在后台发送电子邮件,而是将错误日志写入该新表以使错误更加“集中”。

我想知道您是否认为我实际上在做一个好的实践,或者您是否更喜欢我的第二选择,或者可能都不喜欢,您最好使用第三方错误记录器。

最好的!

0 投票
2 回答
1390 浏览

php - 如何在 PHP 中的 throw new Exception() 中传递一个数组。在异常处理程序中传递数组的最佳方法是什么?

这是我的代码,但它向我发送错误。它说异常处理程序的参数错误。

0 投票
2 回答
308 浏览

ruby-on-rails - Rails exception_handler gem 未更新 404 页面

我正在使用 exception_handler gem 来制作自定义 404 页面。当我转到我网站上的 404 页面时,它显示未找到,但如何自定义此页面?我尝试更改路线,制作 errors_controller 和 not_found 视图。

应用程序.rb

路线.rb

errors_controller.rb

app/views/errors/not_found.html.erb

0 投票
1 回答
842 浏览

python - python - 在日志输出中抑制异常上下文

我有以下测试代码:

执行时(在 Windows 7 下的 Python 2.7.10 中),它将以下回溯信息输出到日志文件:

我有一个双重问题:

  1. 有没有办法抑制异常上下文并只获取最后的回溯?

  2. 我怎样才能只获得引发异常的文件的基本名称(名称+扩展名),而不是带有目录的全名?

总结一下:我想输出到日志文件,如下所示:

提前感谢您提供的任何帮助。

0 投票
1 回答
1028 浏览

spring - Spring ControllerAdvice 没有被异常调用

虽然我定义了 ControllerAdvice 来处理异常,但我没有看到它被调用。这是我的代码,请您指教


控制器建议

我看到 spring 正在创建 GlobalExceptionHandler 对象,但它没有被调用。这是完整代码

我正在使用 Spring 4.3.0 框架并通过 maven 在码头容器中运行。请帮我