jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes What kind posible exception thrown Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What kind posible exception thrown" Watch "What kind posible exception thrown" New topic

What kind posible exception thrown

Ahamed Ali

Joined: Apr 21, 2005
Posts: 19

I would like to know, this code throws which kind of exceptions.

class X
private Vector objects = new Vector();

public void compute ()
Iterator iter = objects.iterator();
while (iter.hasNext()) {
try {
Object o = (Object)iter.next();
catch (Exception ex) {
// under which circumstances will which Exceptions
// be caught here ?

public void addObject (Object o)

Thanks in advance
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
one (crude, but functional) way to find out is to remove the "catch" statement and block, replace it with an empty "finally" statement/block, and try to compile the code. it will not compile, but the compiler will give errors for any checked exceptions that might arise from the "try" block. reading those errors will tell you what you need to worry about, at minimum.

...of course, there's still the possibility of unchecked exceptions being thrown. you'll have to read the documentation for any methods and classes you make use of inside the "try" block to learn about those.
I agree. Here's the link: http://aspose.com/file-tools
subject: What kind posible exception thrown
It's not a secret anymore!