Difference between revisions of "Zh/Documentation/DevGuide/ProUNO/Java/Mapping of Exception Types"

From Apache OpenOffice Wiki
Jump to: navigation, search
(New page: {{Documentation/DevGuide/ProUNOTOC/Zh |ProUNO2c=block |ProUNO2cJava=block |ProUNO2cJavaTM=block |ShowPrevNext=block |PrevPage=Zh/Documentation/DevGuide/ProUNO/Java/Mapping of Struct Types ...)
 
m
 
Line 7: Line 7:
 
|NextPage=Zh/Documentation/DevGuide/ProUNO/Java/Mapping of Interface Types
 
|NextPage=Zh/Documentation/DevGuide/ProUNO/Java/Mapping of Interface Types
 
}}
 
}}
[[en:Documentation/DevGuide/ProUNO/Java/Mapping of Exception Types]]
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/ProUNO/Java/{{SUBPAGENAME}}}}
 
{{DISPLAYTITLE:Mapping of Exception Types}}
 
{{DISPLAYTITLE:Mapping of Exception Types}}
  

Latest revision as of 02:44, 14 May 2009



UNO 异常类型被映射成同名的公共 Java 类。只有对这种类的非空引用才是有效的。


有两个 UNO 异常是其他所有异常的基异常。它们是 com.sun.star.uno.Exceptioncom.sun.star.uno.RuntimeException其他所有异常都是从它们继承的。Java 中的相应异常继承 Java 异常:

 module com { module sun { module star { module uno {
 
 exception Exception {
     string Message;
     XInterface Context;
 };
 
 exception RuntimeException {
     string Message;
     XInterface Context;
 };
 
 }; }; }; };


Java 中的 com.sun.star.uno.Exception

 package com.sun.star.uno;
 
 public class Exception extends java.lang.Exception {
     public Object Context;
 
     public Exception() {}
   
     public Exception(String Message) {
         super(Message);
     }
 
     public Exception(String Message, Object Context) {
         super(Message);
         this.Context = Context;
     }
 }


Java 中的 com.sun.star.uno.RuntimeException

 package com.sun.star.uno;
 
 public class RuntimeException extends java.lang.RuntimeException {
     public Object Context;
 
     public RuntimeException() {}
   
     public RuntimeException(String Message) {
         super(Message);
     }
 
     public RuntimeException(String Message, Object Context) {
         super(Message);
         this.Context = Context;
     }
 }

如示例所示, Message 成员不存在相应的 Java 类。而是使用构造函数参数 Message 来初始化 Java 异常的基类。可通过继承的 getMessage() 方法访问 Message。UNO 异常类型的其他所有成员都被映射成同名称、相应 Java 类型的公共字段。生成的 Java 异常类通常具有一个用默认值初始化所有成员的默认构造函数,以及一个获取所有成员值的构造函数。


如果一个异常继承另一个异常,则生成的类是被继承异常的类的子类。


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