Win a copy of Kotlin in Action this week in the Kotlin forum!
    Bookmark Topic Watch Topic
  • New Topic

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

 
Basavaraju Banakar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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.
 
R Jelda
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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
  • Report post to moderator
Actually I was looking for something that happens in Transactions....
Exactly how Java handles try block in memory?...
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • 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
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!