mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-25 03:11:10 +01:00
Improve exception stack traces in OptimizedMessageNotifier.
This commit is contained in:
@@ -627,4 +627,25 @@ public class Util {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the stack trace of the provided throwable onto the provided primary exception. This is
|
||||
* useful for when exceptions are thrown inside of asynchronous systems (like runnables in an
|
||||
* executor) where you'd otherwise lose important parts of the stack trace. This lets you save a
|
||||
* throwable at the entry point, and then combine it with any caught exceptions later.
|
||||
*
|
||||
* @return The provided primary exception, for convenience.
|
||||
*/
|
||||
public static RuntimeException appendStackTrace(@NonNull RuntimeException primary, @NonNull Throwable secondary) {
|
||||
StackTraceElement[] now = primary.getStackTrace();
|
||||
StackTraceElement[] then = secondary.getStackTrace();
|
||||
StackTraceElement[] combined = new StackTraceElement[now.length + then.length];
|
||||
|
||||
System.arraycopy(now, 0, combined, 0, now.length);
|
||||
System.arraycopy(then, 0, combined, now.length, then.length);
|
||||
|
||||
primary.setStackTrace(combined);
|
||||
|
||||
return primary;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user