• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exceptions !!

 
Ankitt Dhebarr
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Can anyone help me out by telling what will be the output of the above code and how is it step by step so that I can understand it exactly !!
 
Vijay Raj
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Vijay.

[removed some 'not so nice' suggestions]
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


System.out.println("Be Meaningful Please - post your thoughts too");
 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijay Raj wrote:
Vijay.


Vijay, please watch your attitude!
 
Samrat Som
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose We Guys are here to share our knowledge and not pointing out others in such a harsh manner.
 
Harshit Rastogi
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankitt Dhebarr wrote:


Can anyone help me out by telling what will be the output of the above code and how is it step by step so that I can understand it exactly !!


dont be disappointed what other people have told. This fourn is for beginner and any sort of questions can be asked.
coming down to your question:
The output will be :
ABDEF

A & B will be displayed because of normal flow execution then the exception is thrown which is caught by a catch block hence the program flow comes to catch block and 'D' is displayed and not 'C'. The finally block has to be executed in all cases whether the exception is caught or not. So 'E' is displayed and at last the control comes out from try-catch-finally block and 'F' is displayed.
 
Ankitt Dhebarr
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really thank all for your kind support !!
 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harshit Rastogi wrote:

...This fourn is for beginner and any sort of questions can be asked.


Harshit, this is true, however, simply asking for the answers to questions, without trying it oneself, is not a productive method of learning don't you think, after all we shouldn't be doing others homework for them.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12101
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankitt Dhebarr,

Generally, we expect people to ShowSomeEffort. Posting some code and asking 'what is the output' pretty much shows you have put in NO effort. The LEAST you could do is run the code yourself. That way, you would see exactly what the output is. Then, if you don't understand it, you can ask a more focused question, like "I was expecting output A, but got output B and don't understand why".

further, you could tell us which specific part you don't understand. Do you know what System.out.print() does? Do you know what a try/catch block is? what the finally is?

In other words, the more specific your question, the easier it is for someone to help you, and the better response you'll get. You may want to read a lot of this. They really are great suggestions on how to get the most out of this site.

Thanks!!!
 
Flom Xanther
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure this will even compile?

I think it wouldn't compile, because line 10 is surely unreachable code!


Regards,
Flom
 
Priyam Srivastava
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code won't compile. Once you throw a exception at line 9, the control will never go to line 10. To compile you can do this::


 
Apoorv Srivastava
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Won't compile for sure...
Line no 9 is unreachable code..
 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apoorv, surely that depends on what conditional logic he chooses to write that would result in a NumberFormat Exception?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15219
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephen: Note that there's a button on the top right hand side of your post to delete it.
 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OOp's apologies, I didn't notice that ata all thanks for the heads up Jesper!..

..actually I cant see it at the moment..

..sorry Jesper I cant seem to find this button anywhere...
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15219
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm.... I can see that button on all posts, but that's because I'm a moderator. I assumed that as a normal user you would be able to delete your own posts (we had such a feature in the old forum software - since the beginning of this year we have new forum software). I'll ask the other moderators about it.

I deleted the empty post for you.
 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper, much appreciated
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper Young wrote:I assumed that as a normal user you would be able to delete your own posts (we had such a feature in the old forum software - since the beginning of this year we have new forum software). I'll ask the other moderators about it. I deleted the empty post for you.


We are no longer able to delete our own post, with the new forum software according to this (Don't know about any update after that)
 
Jae Lim
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compilation fails
 
Srikanth Munjuluri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone,
firstly I am sorry that a huge matter has been created about nothing......You could have answered and then say Be EXPERIMENTING guy from next time..........
And regarding the question ,this code will not compile.....because of unreachable statement.....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic