Mapping of Exception Types

From Apache OpenOffice Wiki
Jump to: navigation, search



A UNO exception type is mapped to a public Java class with the same name. Only non-null references to such a class are valid.

There are two UNO exceptions that are the base for all other exceptions. These are the com.sun.star.uno.Exception and com.sun.star.uno.RuntimeException that are inherited by all other exceptions. The corresponding exceptions in Java inherit from Java exceptions:

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

The com.sun.star.uno.Exception in Java:

  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;
      }
  }

The com.sun.star.uno.RuntimeException in Java:

  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;
      }
  }

As shown, the Message member has no direct counterpart in the respective Java class. Instead, the constructor argument Message is used to initialize the base class, which is a Java exception. The message is accessible through the inherited getMessage() method. All other members of a UNO exception type are mapped to public fields with the same name and corresponding Java type. A generated Java exception class always has a default constructor that initializes all members with default values, and a constructor which takes values for all members.

If an exception inherits from another exception, the generated class extends the class of the inherited exception.

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