Page 2 of 2 FirstFirst 12
Results 21 to 30 of 30
Like Tree2Likes

Thread: try catch block issue

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

    Default

    Quote Originally Posted by Sheenu Gupta View Post
    Tolls

    He man see what code you r writing and what the member has asked okey then shout.
    My answer is correct all over
    Maybe in your world it is, but it was totally incorrect in the normal world.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  2. #22
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,742
    Rep Power
    19

    Default

    You said:
    "Ist Thing that Finally never returns anything."

    That is incorrect. Entirely incorrect.
    Have you run this code?
    That finally block will always execute and will override any (and all) prior return statements with its own.
    So the answer to the OPs question is you will always get 3.

  3. #23
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Quote Originally Posted by Sheenu Gupta View Post
    Tolls

    He man see what code you r writing and what the member has asked okey then shout.
    My answer is correct all over
    On the contrary, it's wrong all over.

    Quote Originally Posted by Sheenu Gupta View Post
    Ist Thing that Finally never returns anything.
    Wrong. A return statement in a finally block is a sign of extremely poor coding, but that's a different issue.

    The Question asked to you will giver error on execution.
    It won't compile because of the empty parentheses in the catch statement, but again, that's a different issue.

    2nd is that if the condition in try block is correct then It will return 1 and if user does not entered correct according to catch compiler will go to catch block for execution .
    Wrong. Except only if System.exit(...) is invoked, execution will always enter the finally block.

    3rd is if catch block also is unable to catch the error then finally block will execute.
    Wrong. Entering the finally block has nothing to do with whether the Exception was caught.

    Finally block is like default in switches.
    Wrong. There's no similarity at all.

    Now go learn and stop shouting.
    Lesson: Exceptions (The Java™ Tutorials > Essential Classes)

    db

  4. #24
    Sheenu Gupta is offline Member
    Join Date
    Jul 2011
    Location
    Chandigarh
    Posts
    9
    Rep Power
    0

    Default

    Tolls

    It seems you r not understanding what the person is asking. You r just pushing the question. He has asked a simple thing and u r making it so complicated and shouting on others too. And one thing more i my world I am okey and i know better about that you think of urself. Better not to reply again and again on my post.

  5. #25
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Quote Originally Posted by Sheenu Gupta View Post
    Tolls

    It seems you r not understanding what the person is asking. You r just pushing the question. He has asked a simple thing and u r making it so complicated and shouting on others too. And one thing more i my world I am okey and i know better about that you think of urself. Better not to reply again and again on my post.
    Once again, wrong.

    db

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

    Default

    Quote Originally Posted by Sheenu Gupta View Post
    Tolls

    It seems you r not understanding what the person is asking. You r just pushing the question. He has asked a simple thing and u r making it so complicated and shouting on others too. And one thing more i my world I am okey and i know better about that you think of urself. Better not to reply again and again on my post.
    Tolls (and anybody else) is free to reply wherever she or he wants, you have no saying in this. Also, Tolls wasn't pushing the question; he (and others) were completely right and you were wrong.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #27
    Sheenu Gupta is offline Member
    Join Date
    Jul 2011
    Location
    Chandigarh
    Posts
    9
    Rep Power
    0

    Default

    Yes, He might be right but he has not given any authority to shout. He can reply tell what is wrong politely but no shouting.

    Okey got JosAH

  8. #28
    Sheenu Gupta is offline Member
    Join Date
    Jul 2011
    Location
    Chandigarh
    Posts
    9
    Rep Power
    0

    Default

    Hey i have run the program and I am right. That finally block never have return. and it only and only executes when try and catch both are unable to work.

    Ok

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

    Default

    Quote Originally Posted by Sheenu Gupta View Post
    Hey i have run the program and I am right. That finally block never have return. and it only and only executes when try and catch both are unable to work.

    Ok
    Find yourself a compliant Java implementation; you're talking nonsense. A return in the finally block (which is a bad thing by itself) overrules any other return in the try or catch block. Case closed.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #30
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,742
    Rep Power
    19

    Default

    Show us your code.
    Produce a simple bit of code to run (like I did) and show us.

    As for shouting, I did that because we had already explained in this thread why the finally block return is the only one that matters and yet you still posted an erroneus answer.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Try/catch block
    By swati.jyoti in forum New To Java
    Replies: 5
    Last Post: 07-02-2009, 02:32 PM
  2. Question reg try/catch block
    By nn12 in forum New To Java
    Replies: 1
    Last Post: 09-16-2008, 05:56 PM
  3. System.exit() in catch block.
    By new_2_java in forum Advanced Java
    Replies: 8
    Last Post: 06-24-2008, 03:45 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
  •