in reply to java inline printstacktrace

I found the solution. Share with everyone.

eval { #call java jar file }; if ($@){ print " Getting error ...\n"; if ( caught("java.lang.Throwable") ) { # have to save it; otherwise value will change after t +he following two lines my $exception = $@; my $msg = $exception->getMessage(); my $string_writer = new java::io::StringWriter(); my $print_writer = new java::io::PrintWriter($string_w +riter); $exception->printStackTrace($print_writer); my $line = $string_writer->toString(); $errorLog->error($msg . "\n" . $line); } }

Replies are listed 'Best First'.
Re^2: java inline printstacktrace
by ikegami (Patriarch) on Mar 30, 2010 at 15:49 UTC
    Sounds like ->getMessage(), java::io::StringWriter::new or java::io::PrintWriter::new was using eval and clobbering $@, thus the need to copy it.
      That was the theory put forward on the Inline mailing list.