Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 922631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:03:52+00:00 2026-05-15T19:03:52+00:00

I am using Com4J to interact with Microsoft Outlook. I have generated the Java

  • 0

I am using Com4J to interact with Microsoft Outlook. I have generated the Java type definitions as per the Com4J tutorial. Here is an example of some code that waits for the user to close an email.

// Registers my event handler
mailItem.advise(
        ItemEvents.class,
        new ItemEvents() {
            @Override
            public void close(Holder<Boolean> cancel) {
                // TODO Auto-generated method stub
                super.close(cancel);
                System.out.println("Closed");
            }
        }
    );

// Displays the email to the user
mailItem.display();

This code successfully displays the email to the user. Unfortunately, my program never prints "Closed" when the user closes the window.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:03:53+00:00Added an answer on May 15, 2026 at 7:03 pm

    When Com4J generates an event class (ItemEvents in my scenario), the default behavior for all generated methods is to throw an UnsupportedOperationException (see the com4j.tlbimp.EventInterfaceGenerator class for details).

    For example, here is the close method of the ItemEvents class that my anonymous class overrides:

    @DISPID(61444)
    public void close(Holder<Boolean> cancel) {
        throw new UnsupportedOperationException();
    }
    

    Therefore, when my anonymous class calls super.close(cancel);, the parent class throws an UnsupportedOperationException, preventing execution from reaching my System.out.println("Closed"); statement. Therefore, my anonymous class should really have looked like this:

    mailItem.advise(
            ItemEvents.class,
            new ItemEvents() {
                @Override
                public void close(Holder<Boolean> cancel) {
                    System.out.println("Closed");
                }
            }
        );
    

    What surprised me is that Com4J appears to have simply ignored the UnsupportedOperationException thrown from the event handler altogether, leaving me no indication of what actually happened. I wrote this code to demonstrate:

    mailItem.advise(
            ItemEvents.class,
            new ItemEvents() {
                @Override
                public void close(Holder<Boolean> cancel) {
                    System.out.println("Getting ready to throw the exception...");
                    throw new RuntimeException("ERROR! ERROR!");
                }
            }
        );
    

    The program emits this output:

    Getting ready to throw the exception...

    However, there is no indication that a RuntimeException was ever thrown.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using com4j to generate Java type definitions from a COM type library. The
Using Java,I have to fetch multiple sets of values from an XML file to
Im am trying to generate interfaces of HP Quality Center OTACLien.dll using com4j. I
Using a populated Table Type as the source for a TSQL-Merge. I want to
I'm trying to interact with a webcam from Java on Windows (without going through
Using android 2.3.3, I have a background Service which has a socket connection. There's
I have to connect the Arduino board I got with Java and get data
Using MVC2 I have an AJAX form which is posting to a bound model.
Using Core Data, I have a fetch request to fetch the minimum of a
Using MVVM. I have a DataTemplate which I am using to display an expander

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.