I have long hierarchy of exceptions, one of it add long message with binary data. I can't change it in throw place, since it's in library. How can i truncate it, without losing another exceptions messages?
code example:
throw new RuntimeException("msg",
new RuntimeException(generateLongErrorMessage(),
new RuntimeException("short message",
new RuntimeException("important message"))
)
);
desired output:
Exception in thread "main" java.lang.RuntimeException: msg
at xxx.excpetionMessageTruncator(Erofeev.java:18)
at xxx.main(Erofeev.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.RuntimeException: long message long message ...(truncated, original size: 100)
... 7 more
Caused by: java.lang.RuntimeException: short message
... 7 more
Caused by: java.lang.RuntimeException: important message
... 7 more