• 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

finally { } clause in Exceptions

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And WHY is the finally clause executed if NO condition for an exception
is fullfilled AS i=2 => break!!!

finally clauses are always executed unless you call System.exit in your catch block (which I do not recommend).

Gotta run.
[ August 04, 2002: Message edited by: Marilyn de Queiroz ]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thomas,
Note that the finally block is always executed, even if the try or catch block returns. As Marilyn noted, it's only not called when the try or catch block shuts down the JVM with a call to System.exit( int ) or if a very serious error condition is raised, such as running out of memory, which also causes the JVM to shut down (I think).
Also, to make your posts even easier to read, you may only want to surround actual code blocks with the [code] and [/code] UBB Tags.
Good Luck.
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can only have zero or one finally for each try statement, and only one catch statement will execute for each try (which is why you should catch the most specific one first if you have more than one). That's just the way it is.

try{
}
catch ( SpecificException se ){ // i.e. FileNotFoundException
}
catch ( GeneralException ge ){ // i.e. IOException
}
catch ( Exception e ){ // i.e. Exception
}
finally{
}

try executes, then one of the catch statements, then finally.
[ August 04, 2002: Message edited by: Marilyn de Queiroz ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic