Results 1 to 7 of 7
  1. #1
    egrizzly is offline Member
    Join Date
    Jun 2016
    Posts
    10
    Rep Power
    0

    Default Help with Homework Question-Exceptions

    Can somebody assist me in finding out the best answer for Q4)Which of the following catch blocks are correctly ordered?

    I thought option "e" was the best answer since it started with the most precise Exception type, however it has ArithmeticException as the second in the list making it a tough pick compared with option "d". Please say why you think your selected answer is the best choice. I attached the picture, pdf documents and also have a dropbox link below.


    https://www.dropbox.com/s/0eco2sx064...c%207.jpg?dl=0
    Attached Thumbnails Attached Thumbnails Help with Homework Question-Exceptions-exceptions7.jpg  
    Attached Files Attached Files

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Help with Homework Question-Exceptions

    Well, which comes first? Grabbing the input or performing the operation?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    egrizzly is offline Member
    Join Date
    Jun 2016
    Posts
    10
    Rep Power
    0

    Default Re: Help with Homework Question-Exceptions

    Quote Originally Posted by jim829 View Post
    Well, which comes first? Grabbing the input or performing the operation?

    Regards,
    Jim
    you're given a set of Exceptions to chose from as the answer and asked to select which answer set is the best fit. The exception tree is shown
    at the tree diagram. Of course the rule in java is to always pick the more specific exceptions first before the general ones...hence my dilemma.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Help with Homework Question-Exceptions

    Does it actually matter?
    They're both valid, aren't they?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    egrizzly is offline Member
    Join Date
    Jun 2016
    Posts
    10
    Rep Power
    0

    Default Re: Help with Homework Question-Exceptions

    Quote Originally Posted by Tolls View Post
    Does it actually matter?
    They're both valid, aren't they?
    It does matter because it will certainly be a test question. yes, they seem to be both valid to me but the professor only picked one right answer.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Help with Homework Question-Exceptions

    Ok, here is my take on this. Logically, you need to ensure that the input is valid before you do anything with it. And you can only get an arithmetic exception once you start to do something with it that is bad. So (e) looks good.

    However, both AE and NSEE are unrelated and at the same level in the hierarchy so they can be swapped. IME must precede NSEE or it will never be reached. And Exception must clearly be at the end.

    Finally and as usual, I could be totally wrong on this.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Help with Homework Question-Exceptions

    Quote Originally Posted by egrizzly View Post
    It does matter because it will certainly be a test question. yes, they seem to be both valid to me but the professor only picked one right answer.
    Then ask him why, because either of those are valid, both stylistically and logically.
    In both cases you are applying the exceptions a branch at a time.
    Any choice is pretty much arbitrary.
    I suspect you'd end up with (e) if you were writing the code simply because, as jim says, you may well write the input code first, but then someone else may write the calculation first, in which case the AE would be the first in the list.

    I'm curious what your teachers logic is for there being only one correct answer.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Question About Exceptions
    By ShadowWalker in forum New To Java
    Replies: 5
    Last Post: 02-15-2014, 08:11 PM
  2. Java homework question
    By Mavor in forum New To Java
    Replies: 4
    Last Post: 10-09-2013, 02:18 PM
  3. Exceptions Question
    By Clown in forum New To Java
    Replies: 2
    Last Post: 02-19-2013, 09:42 AM
  4. question regarding exceptions..
    By SCS17 in forum New To Java
    Replies: 3
    Last Post: 11-17-2007, 09:31 AM
  5. Question on Exceptions
    By yelllow4u in forum New To Java
    Replies: 6
    Last Post: 07-27-2007, 01:41 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
  •