• Post Reply Bookmark Topic Watch Topic
  • New Topic

Runtime Exeption silly question  RSS feed

 
Kamila Bertran
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello there! Long time no read.

I just need to clear my doubts about a certain exception handling issue.
Let's say I try to write a simple piece of code just to see how exactly this thing works and I come up with something like this:




So the conclusion being is that if I do have an exception occurring (like here it obviously does occur) than the whole block of code in 'try' will not execute? Therefore c will have a value 11?

That exception handling is still bit of a magic to me and therefore undoubtedly I fill fail on the exam but hopefully I will grasp it sometime soon.
 
Kamila Bertran
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see what's happening there now. If I had a++, and than tried to a the length of a null string than all the code up to the moment that exception occurs gets executed.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is c? Did you mean a?
I suggest you add something to your catch: e.printStackTrace(); That will allow you to see that the Exception is occurring. If you still need confirmation, write down the value of a at the beginning and the end of each line as you go through the code. The full details are in the Java® Language Specification, but that is by no means easy to understand. Simply:-
  • 1: you initialise a to 10
  • 2: You attempt to reassign a, but suffer an Exception.
  • 3: The program state reverts to what it was at the beginning of the line, so a reverts to 10.
  • 4: You know enough programming to be able to work out the rest of the flow of execution yourself henceforth.
  •  
    Consider Paul's rocket mass heater.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!