Am 23.12.20 um 19:23 schrieb Tong Sun:
> On Wed, Dec 23, 2020 at 1:19 PM Felix Schumacher
> <[email protected]> wrote:
>>
>> Am 23.12.20 um 19:16 schrieb Tong Sun:
>>> Hi,
>>>
>>> Most people would have some Java code to support JMeter test scripts.
>>> How to print stack trace for the Java code when something went wrong?
>>>
>>> I tried:
>>>
>>> try {
>>> // some code
>>> } catch(Error e) {
>>> log.error("Error: $e")
>>> log.info("${org.codehaus.groovy.runtime.StackTraceUtils.sanitize(new
>>> Exception(e)).printStackTrace()}")
>>> }
>>>
>>> base on
>>> https://stackoverflow.com/questions/6259202/how-do-i-print-a-groovy-stack-trace
>>> and also `e.printStackTrace()` from Java, but both print out just "null"
>> Where would you place those code? If you use that inside of JMeter
>> JSR-223 scripts, you will get bitten by JMeter replacing the ${...} stuff.
> Yeah, exactly in the JSR-223 scripts.
>
> I put merely
>
> org.codehaus.groovy.runtime.StackTraceUtils.sanitize(new
> Exception(e)).printStackTrace()
I always do one of the following (in a JSR-223 Groovy script):
try {
1 / 0 // throw an exception
} catch(e) {
log.info("Ooops: " + e); // without stacktrace
log.info(Ooops: " + e, e); // with stacktrace
}
but if you are afraid of the Groovy methods in the stacktrace, you can use
log.info("OOOps: " + ,
org.codehaus.groovy.runtime.StackTraceUtils.sanitize(e))
The sanitize method works on the original excpetion (in this case e) and
gives back a new exception with a sanitized stacktrace.
Felix
>
> before but nothing get printed in log, so I changed to log.info instead.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]