为什么这个小程序在命令行窗口和eclipse中运行结果不同呢?

来源:百度知道 编辑:UC知道 时间:2024/06/14 08:13:45
public class UsingException {
public static void main(String args[]){
try{
throwException();
}
catch(Exception e){
System.err.println("Exception handled in main");
}
doesNotThrowException();
}
public static void throwException()throws Exception{
try{
System.out.println("Method throwException");
throw new Exception();
}
catch(Exception e){
System.err.println("Exception handled in method throwExcelption");
throw e;
}
finally{
System.err.println("Finally exxcuted in throwThrowException");
}
}
public static void doesNotThrowException(){
try{
System.out.println("Method doesNotThrowException");
}
catch(Exception e){
System.err.println(e.toString());
}
finally{
System.err.println("Finally executed in doesNotThrowExcepti

如果把System.out都换成System.err,或者将System.err都换成System.out,那么在Eclpise上运行的结果和书上是一样的。

研究了一下,System.out和System.err并没有什么本质区别,应该是Eclipse工具的问题,呵呵。

使用的JDK不一样吧,eclipse是自带的么?建议改下一样的