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 6900969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:36:52+00:00 2026-05-27T07:36:52+00:00

I have the following piece of code. I would like to know what sort

  • 0

I have the following piece of code. I would like to know what sort of exceptions would be caught inside the catch block in a multithreaded enviorment.

class Goo
{
private Vector objects = new Vector();

public void kempute ()
{
    Iterator iter = objects.iterator();
    while (iter.hasNext()) {
        try {
            Object o = (Object)iter.next();
            System.out.println(o.hashCode());
        }
        catch (Exception ex) {
            //
        }
    }
}

public void addme (Object o)
{
    objects.add(o);
}
}

I really couldnt find any exceptions. Any help is really appreciated.

  • 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-27T07:36:53+00:00Added an answer on May 27, 2026 at 7:36 am

    An exception could be caught at that point if

    Object o = (Object)iter.next();
    

    or

    System.out.println(o.hashCode());
    

    throw an unchecked exception. Here are a couple of possibilities:

    • If you had previously called addObject(null), a call to update() would lead to a NullPointerException when it calls hashCode() on a null reference.

    • If you have an instance of Foo shared by two threads, and one calls addObject while the other is calling compute(), then you could get a ConcurrentModificationException.

    • If Vector was a custom class and not java.util.Vector, then iter.next() could throw some other unchecked exception … at the whim of the author of said custom class. (OK … unlikely in the light of the OP’s comments.)

    • (From aix’s answer) – o.hashCode() could in theory throw any unchecked exception, depending on how o‘s class implements the hashCode() method.

    • There may be other possibilities too.


    If you are merely curious as to what the possible exceptions might be, the above more or less covers it.

    If you want to tidy up this code, then it is probably a bad thing to be catching Exception at that point. Each of those cases listed is a sign of a bug here or elsewhere in the application. Rather that catching the exception at that point and (presumably) trying to “make good” the problem, it is better to bomb out with a stacktrace, and then go back and fix the root problem that was being hidden by the catch.

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

Sidebar

Related Questions

I have a the following piece of code using ncurses. I would like to
I have the following piece of code: NameX.functionA(functionB(Dictionary[___])) Instead of _ I would like
I have the following piece of code that I would like help with... public
I have the following code piece for a console application that I would like
I have the following piece of code for a graph: barplot(as.vector(t(mat1[1,3:ncol(mat1)])),las=2) that I would
I have following piece of code: It compiles without problems under gcc-3.4, gcc-4.3, intel
I have following piece of code : public Hashmap<String,String> tempmap = new HashMap<String,String>(); and
I have the following piece of code that takes in some words, stores them
I have the following piece of code in my Model: public function getSite() {
I have the following piece of code where i am concatenating events to the

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.