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

Too big try catch blocks Vs number of small try catch blocks

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
What is the overhead of having a lot of code in a single try block and catch all the exceptions that are thrown in seperate catch blocks??

Would it be better to have seperate try/catch blocks to handle each chunck of code that potentially throws an exception.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I prefer a single big try catch block.
Its straight forward and not buggy especially, easily maintainable.
Hopefully we get some performance too..
Regards,
Jelda
 
Basavaraju Banakar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Actually I was looking for something that happens in Transactions....
Exactly how Java handles try block in memory?...
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I don't think you can generalize about which is better - it depends on what information you need to recover from the exception.
Bill
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please don't post the same question in different forums. It wastes time for people who answer in one forum without knowing the same point has already been made in another forum.
I think the performance implications of small vs. large try/catch block are really unimportant compared to other issues like correctness of code, and readability, so I'm closing this thread and directing followups to the thread in Java in General (intermediate) since that's better suited to the topic in general.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic