异常

From Apache OpenOffice Wiki
Jump to: navigation, search



exception 类型表示函数调用程序发生错误。异常类型给出发生的错误类型的基本说明。另外,UNO IDL exception 类型包含的元素给出精确规范和错误详细说明。exception 类型支持继承,这常用于定义错误分层。异常仅用于指出错误,不作为方法参数或返回类型。


UNO IDL 要求所有异常都必须从 com.sun.star.uno.Exception 继承。这是 UNO 运行时的一个前提。

  // com.sun.star.uno.Exception is the base exception for all exceptions
  exception Exception {
      string Message;  
      Xinterface Context;
  };
 
  // com.sun.star.uno.RuntimeException is the base exception for serious problems
  // occuring at runtime, usually programming errors or problems in the runtime environment
  exception RuntimeException : com::sun::star::uno::Exception {
  };
 
  // com.sun.star.uno.SecurityException is a more specific RuntimeException 
  exception SecurityException : com::sun::star::uno::RuntimeException {
  };

异常只能由指定抛出异常的操作来抛出。而 com.sun.star.uno.RuntimeException 则可以随时发生。


Documentation caution.png UNO 基接口 com.sun.star.uno.XInterface 的方法 acquire() 和 release 是上述规则的例外。它们是唯一不会抛出运行时异常的操作。但在 Java 和 C++ 程序中,不直接使用这些方法,而是由各自的语言绑定进行处理。


Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages