admin管理员组

文章数量:1122846

In some cases exceptions being thrown are causing crashes in native library that we use before they get to be logged anywhere. So waiting for UncaughtExceptionHandler to log them won't work. Even exceptions that were eventually caught caused crashes in native code in a few cases. And crash logs generated have no info on these exceptions.

Is there any way to log all exceptions as soon as they are created? Preferably it needs to work in a release build, without attached debugger.

In some cases exceptions being thrown are causing crashes in native library that we use before they get to be logged anywhere. So waiting for UncaughtExceptionHandler to log them won't work. Even exceptions that were eventually caught caused crashes in native code in a few cases. And crash logs generated have no info on these exceptions.

Is there any way to log all exceptions as soon as they are created? Preferably it needs to work in a release build, without attached debugger.

Share Improve this question edited Nov 22, 2024 at 9:54 jonrsharpe 122k30 gold badges263 silver badges470 bronze badges asked Nov 22, 2024 at 9:53 maxpovvermaxpovver 1,6001 gold badge15 silver badges25 bronze badges 6
  • 1 stackoverflow.com/a/58325793/21105992 <- implement your own java.lang.Throwable class? – teapot418 Commented Nov 22, 2024 at 10:11
  • 2 Perhaps you should explain in more detail about "causes crashes in native library". How does throwing an exception do that? – greg-449 Commented Nov 22, 2024 at 10:13
  • 2 You don't want to do it. There are many exception thrown and caught in libraries. Even in SDK. – talex Commented Nov 22, 2024 at 10:32
  • 4 You should fix the bugs in the native library, for sure. It should not crash due to some exception being thrown, not to speak of exceptions throw and caught somewhere (which suggests that they are entirely unrelated to the native library). – Holger Commented Nov 22, 2024 at 12:30
  • 1 @maxpovver This does not change the fact that the bugs in the native library should be fixed rather than wasting time with the symptoms. – Holger Commented Nov 25, 2024 at 15:08
 |  Show 1 more comment

1 Answer 1

Reset to default 1

If you know what methods are called from native code you can add try catch in them.

You don't need to do it manually if you use some AOP library.

本文标签: How to log all Java exceptions on creationStack Overflow