I have observed that both the statements are valid. What is the extra thing logged in the first statement compared to the second one?
我已经注意到,这两个表述都是有效的。与第二个语句相比,第一个语句中记录的额外内容是什么?
3 个解决方案
#1
4
The first one also logs the original exception (and stacktrace), the second one only the message.
第一个还记录了原始异常(和堆栈跟踪),第二个也是唯一的消息。
So, the 'extra thing' logged in the first statement is the original exception. This is generally a good thing to do, since this makes it easier to debug the error.
因此,在第一个语句中记录的“额外的东西”是原始的异常。这通常是一件好事,因为这样可以更容易地调试错误。
#2
0
According to documentation
根据文档
void error(Object message) => Logs a message with error log level.
void error(对象消息)=>记录一个带有错误日志级别的消息。
void error(Object message, Throwable t) => Logs an error with error log level.
无效错误(对象消息,可转换的t) =>记录错误日志级别。
I think this might solve your doubt.
我想这也许能解决你的疑问。
#3
0
If you use the method with throwable parameter the support team will be deeply grateful to you. The second one only prints the cause of the Exception, the first one shows the stacktrace.
如果你使用的是可投掷参数的方法,支持团队将会非常感谢你。第二个文件只打印异常的原因,第一个显示堆栈跟踪。
If you use the second one inside a try / catch you probably are hiding the original Exception because it only prints the message of the first exception.
如果在try / catch中使用第二个,可能隐藏了原来的异常,因为它只输出第一个异常的消息。
#1
4
The first one also logs the original exception (and stacktrace), the second one only the message.
第一个还记录了原始异常(和堆栈跟踪),第二个也是唯一的消息。
So, the 'extra thing' logged in the first statement is the original exception. This is generally a good thing to do, since this makes it easier to debug the error.
因此,在第一个语句中记录的“额外的东西”是原始的异常。这通常是一件好事,因为这样可以更容易地调试错误。
#2
0
According to documentation
根据文档
void error(Object message) => Logs a message with error log level.
void error(对象消息)=>记录一个带有错误日志级别的消息。
void error(Object message, Throwable t) => Logs an error with error log level.
无效错误(对象消息,可转换的t) =>记录错误日志级别。
I think this might solve your doubt.
我想这也许能解决你的疑问。
#3
0
If you use the method with throwable parameter the support team will be deeply grateful to you. The second one only prints the cause of the Exception, the first one shows the stacktrace.
如果你使用的是可投掷参数的方法,支持团队将会非常感谢你。第二个文件只打印异常的原因,第一个显示堆栈跟踪。
If you use the second one inside a try / catch you probably are hiding the original Exception because it only prints the message of the first exception.
如果在try / catch中使用第二个,可能隐藏了原来的异常,因为它只输出第一个异常的消息。