try{...}
catch{...
System.out.println(ex);
.}

解决方案 »

  1.   

    try{
    ...
    }catch(Exception e){System.out.println("错误原因:"+e.toString())}
    或者是e.printStackTrace()
      

  2.   

    e.printStackTrace()是什么意思?
    另外在catch{}中,System.out.println()与out.println()有何区别?
    我感觉out.println()会在网面里打印出来。而System.out.println()会在哪里打印出来?
    他们为什么会在不同的地方打印例外信息,这是怎么回事?我彻底糊涂了
      

  3.   

    e.printStackTrace()是什么意思?是打印堆栈。
    System.out.println()与out.println()有何区别?
    前者打印到后台。后者输出到页面。
      

  4.   

    System.out.println("错误原因:"+e.toString())
    --------------------------------------------------------这个只是打印出异常的类型,并不会指明具体哪一行出错
      

  5.   

    e.printStackTrace();Prints this Throwable and its backtrace to the standard error stream. This method prints a stack trace for this Throwable object on the error output stream that is the value of the field System.err. The first line of output contains the result of the toString() method for this object. Remaining lines represent data previously recorded by the method fillInStackTrace(). The format of this information depends on the implementation, but the following example may be regarded as typical: 
     java.lang.NullPointerException
             at MyClass.mash(MyClass.java:9)
             at MyClass.crunch(MyClass.java:6)
             at MyClass.main(MyClass.java:3)
     This example was produced by running the program: 
     
     class MyClass {
     
         public static void main(String[] argv) {
             crunch(null);
         }
         static void crunch(int[] a) {
             mash(a);
         }
     
         static void mash(int[] b) {
             System.out.println(b[0]);
         }
     }