Hasty Briefsbeta

Bilingual

Is there a cost to try catch blocks?

10 months ago
  • #benchmarking
  • #exception-handling
  • #performance
  • The article explores the performance cost of using try-catch blocks in code that does not throw exceptions.
  • Benchmarking was conducted using the Beale function to compare performance with and without try-catch blocks.
  • Results showed minimal performance degradation (average 1.6%) when using try-catch blocks in non-exceptional cases.
  • The author considered adding a 'safe mode' helper function to handle exceptions but decided against it due to potential performance hits and lack of meaningful feedback.
  • The conclusion is that it's better to handle exceptions explicitly in the objective function rather than relying on a generic try-catch wrapper.