• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Exceptions !!

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !!

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vijay.

[removed some 'not so nice' suggestions]
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


System.out.println("Be Meaningful Please - post your thoughts too");
 
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vijay Raj wrote:
Vijay.



Vijay, please watch your attitude!
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13013
66
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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::


 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apoorv, surely that depends on what conditional logic he chooses to write that would result in a NumberFormat Exception?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jesper, much appreciated
 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Compilation fails
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic