Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Fubarable

Thread: How to write two exceptions in only one catch block?

  1. #1
    emily.m is offline Member
    Join Date
    Feb 2012
    Posts
    9
    Rep Power
    0

    Question How to write two exceptions in only one catch block?

    Hi guys,
    we can write one try block with two catch blocks
    try
    { code body}
    catch(MalformedURLException e)
    {}
    catch(IOException e)
    {}

    Is there a way to do just like above but with only one catch block?
    Thanks in advance,

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    emily.m is offline Member
    Join Date
    Feb 2012
    Posts
    9
    Rep Power
    0

    Default Re: How to write two exceptions in only one catch block?

    Java SE Development Kit 6.0 (JDK)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,508
    Blog Entries
    7
    Rep Power
    20

    Default Re: How to write two exceptions in only one catch block?

    Quote Originally Posted by emily.m View Post
    Java SE Development Kit 6.0 (JDK)
    Nope, Java 1.6 can't do it; as Fubarable already indicated, Java 1.7 can do it. Here's what the 'Coin' proposal has to say about it: link.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    emily.m is offline Member
    Join Date
    Feb 2012
    Posts
    9
    Rep Power
    0

    Default Re: How to write two exceptions in only one catch block?

    Thanks Jos,

Similar Threads

  1. try catch block issue
    By srivempala in forum Advanced Java
    Replies: 29
    Last Post: 07-22-2011, 06:45 PM
  2. Try/catch block
    By swati.jyoti in forum New To Java
    Replies: 5
    Last Post: 07-02-2009, 02:32 PM
  3. Question reg try/catch block
    By nn12 in forum New To Java
    Replies: 1
    Last Post: 09-16-2008, 05:56 PM
  4. Try Catch block issues
    By kewlgeye in forum New To Java
    Replies: 11
    Last Post: 04-29-2008, 07:10 AM
  5. try...catch block
    By javaplus in forum New To Java
    Replies: 3
    Last Post: 11-06-2007, 07:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •