Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>An exception could be caught at that point if</p> <pre><code>Object o = (Object)iter.next(); </code></pre> <p>or </p> <pre><code>System.out.println(o.hashCode()); </code></pre> <p>throw an unchecked exception. Here are a couple of possibilities:</p> <ul> <li><p>If you had previously called <code>addObject(null)</code>, a call to <code>update()</code> would lead to a NullPointerException when it calls <code>hashCode()</code> on a <code>null</code> reference. </p></li> <li><p>If you have an instance of <code>Foo</code> shared by two threads, and one calls <code>addObject</code> while the other is calling <code>compute()</code>, then you could get a <code>ConcurrentModificationException</code>.</p></li> <li><p>If <code>Vector</code> was a custom class and not <code>java.util.Vector</code>, then <code>iter.next()</code> 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.)</p></li> <li><p>(From aix's answer) - <code>o.hashCode()</code> could in theory throw any unchecked exception, depending on how <code>o</code>'s class implements the <code>hashCode()</code> method.</p></li> <li><p>There may be other possibilities too.</p></li> </ul> <hr> <p>If you are merely curious as to what the possible exceptions might be, the above more or less covers it.</p> <p>If you want to tidy up this code, then it is probably a bad thing to be catching <code>Exception</code> 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 <em>fix</em> the root problem that was being hidden by the catch.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload