日期:2014-05-20  浏览次数:20740 次

初学者 异常处理问题
public class FirstUnoContact
{
public static void main (String[] args)
{
try
{
//get the remote office component context
System.out.println ("Bootstrap ..."); //这里运行
com.sun.star.uno.XComponentContext xContext =
com.sun.star.comp.helper.Bootstrap.bootstrap ();
System.out.println ("Connected to a running office ..."); //这里却没运行
com.sun.star.lang.XMultiComponentFactory xMCF =
xContext.getServiceManager ();
String available = (xMCF != null ? "available" : "not available");
System.out.println ("remote ServiceManager is " + available);
}
catch (java.lang.Exception e)
{
System.out.println ("Exception ..."); //这里没有运行,证明没有发生异常?
e.printStackTrace ();
}
finally
{
System.out.println ("exit ..."); //直接运行这里
System.exit (0);
}
}
}

以上代码的结果是:
Bootstrap ...
exit ...

我感到不解的是 既然没有发生异常跳转到catch块 为什么不能够顺序的执行下去,从而运行System.out.println ("Connected to a running office ...");这一句呢?

------解决方案--------------------
你是不是间接调用了JNI方法?
C或C++模块中的本地异常Java是捕捉不到的。
------解决方案--------------------
那就奇了,如果都在Java中,没有什么异常可以逃脱catch (java.lang.Exception e)的。
------解决方案--------------------
你把System.exit (0); 取消看看,是不是出runtimeException
------解决方案--------------------
为什么要使用这个啊

System.exit (0); 

把这个删掉试试
------解决方案--------------------
更奇了,为啥简单一点的程序就不会?
Java code
public class Test {
    public static void main(String[] args) {
        try {
            throw new ClassNotFoundException();
        } catch (java.lang.Exception e) {
            e.printStackTrace();
        } finally {
            System.out.println("end...");
            System.exit(0);
        }
    }
}