Catching More Than One Exception in One Catch Block

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Sweetpin2
Posts: 27
Joined: Thu Feb 07, 2013 9:46 pm
Contact:

Catching More Than One Exception in One Catch Block

Post by Sweetpin2 »

Hi,

Why below code is giving compilation error at catch statement

try{
// some of my codes

}catch(IOException|SQLException ex){

ex.printStackTrace();
}

I am getting below compilation error

IOException.SQLException cannot be resolved to a type
- Syntax error on token "|", . expected

As per the API we can have multiple exception handling in one catch.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Catching More Than One Exception in One Catch Block

Post by admin »

Are you sure you are using Jdk7 to compile?

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests