0

There is a unit of a code

        catch (SQLException e) 
        {
            System.out.println("Connection Failed! Check output console");
            e.printStackTrace();
        }

How to output result of execution of the operator in the file

e.printStackTrace();

?

  • 1
    You really don't want to output `e.printStackTrace()` to a file, and can't unless you redirecting the standard error stream to your file. Better I think to log the stacktrace using logging using either the logging that comes with Java or a 3rd party log utility. – Hovercraft Full Of Eels Jun 04 '13 at 21:26
  • 1
    ^^ See: http://stackoverflow.com/questions/10477607/avoid-printstacktrace-use-a-logger-call-instead – Brian Roach Jun 04 '13 at 21:29
  • @BrianRoach's suggestion and link is what I meant to say! – Hovercraft Full Of Eels Jun 04 '13 at 21:29
  • 1
    That said, this Q is a dup: possible duplicate of [How to write exception(printStackTrace()) into txt file in java?](http://stackoverflow.com/questions/12053075/how-to-write-exceptionprintstacktrace-into-txt-file-in-java) – Brian Roach Jun 04 '13 at 21:30
  • @HovercraftFullOfEels You can use `e.printStackTrace(new PrintStream(new File(filename)))` – gparyani Jun 04 '13 at 22:00

0 Answers0