• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exceptions doubt

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





I have got trouble in understanding the above program.When I run the program the output is

In
doing finally
out

But,I didn�t give any exception thrown in try block.How come the catch block is executed and given the above result?

Please share your knowledge to get me understand.

Thanks,
Shiva.
 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shiva, first thing first, please properly indent your code. It is very difficult to read it this way.

The output is correct as you have initialized the s static string as null and inside the main() method you are calling substring() method which requires an instance of string object. Hence NullPointerException

HTH.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ankur Bhatt:
Shiva, first thing first, please properly indent your code. It is very difficult to read it this way...


Yes, you can use Code Tags to keep your formatting intact.

EDIT: Oh, I see you did use Code Tags. But didn't indent? :roll:
[ February 24, 2006: Message edited by: marc weber ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic