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

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
 
Line 13: Line 13:
  
 
There are two UNO exceptions that are the base for all other exceptions. These are the <idl>com.sun.star.uno.Exception</idl> and <idl>com.sun.star.uno.RuntimeException</idl> that are inherited by all other exceptions. The corresponding exceptions in Java inherit from Java exceptions:
 
There are two UNO exceptions that are the base for all other exceptions. These are the <idl>com.sun.star.uno.Exception</idl> and <idl>com.sun.star.uno.RuntimeException</idl> that are inherited by all other exceptions. The corresponding exceptions in Java inherit from Java exceptions:
 
+
<syntaxhighlight lang="idl">
 
   module com { module sun { module star { module uno {
 
   module com { module sun { module star { module uno {
 
    
 
    
Line 27: Line 27:
 
    
 
    
 
   }; }; }; };
 
   }; }; }; };
 
+
</syntaxhighlight>
 
The <idl>com.sun.star.uno.Exception</idl> in Java:
 
The <idl>com.sun.star.uno.Exception</idl> in Java:
 
+
<syntaxhighlight lang="java">
 
   package com.sun.star.uno;
 
   package com.sun.star.uno;
 
    
 
    
Line 46: Line 46:
 
       }
 
       }
 
   }
 
   }
 
+
</syntaxhighlight>
 
The <idl>com.sun.star.uno.RuntimeException</idl> in Java:
 
The <idl>com.sun.star.uno.RuntimeException</idl> in Java:
 
+
<syntaxhighlight lang="java">
 
   package com.sun.star.uno;
 
   package com.sun.star.uno;
 
    
 
    
Line 65: Line 65:
 
       }
 
       }
 
   }
 
   }
 
+
</syntaxhighlight>
 
As shown, the <code>Message</code> 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 <code>getMessage()</code> 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.
 
As shown, the <code>Message</code> 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 <code>getMessage()</code> 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.
  

Latest revision as of 12:46, 23 December 2020



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