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 ...");这一句呢?
{
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 ...");这一句呢?
C或C++模块中的本地异常Java是捕捉不到的。
com.sun.star.comp.helper.Bootstrap.bootstrap (); 是staroffice的UNO组件 staroffice是c++写的 但这一步好像还没涉及到对c++程序的调用
我再研究一下 谢谢了
果然出现了ClassNotFoundException不过不明白的是 为什么加上了System.exit (0);就不打印异常了呢?
发现异常后不是应该先执行catch块 后无论有无异常再走finally块吗?
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);
}
}
}