Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Performance on Errors

It would appear that catching an error is slower that performing a check prior to the error (for example a TryParse). The related questions that prompt this observation are here and here.

Can anyone tell me why this is so - why is it more costly to catch an error that to perform one or many checks of the data to prevent the error?

like image 300
Paul Michaels Avatar asked May 10 '26 02:05

Paul Michaels


1 Answers

Basically, it's the unwinding of the stack that's most expensive. Here's a great link: Why are try blocks expensive?

like image 180
dcp Avatar answered May 11 '26 16:05

dcp