Does Try Catch influence performance?

Asked

Viewed 133 times

-1

Utilise Try...Catch influence on performance? in memory usage?

Would be a problem if all actions you do have error handling?

  try
  {
    clienteRepository.Salvar(entity);
  }
  catch (Exception e)
  {
    emailService.EnviaErro(e);
  }
  • @bfavaretto is not duplicate, I think the edition you made became clearer

  • Exactly Caffé, my idea would be in exception, send me email with the mistake that happened, rs

  • 1

    A suggestion: when developing web applications, worry about system design and data traffic cost, not with micro-optimization-prior-dubious code performance.

  • Thank you Caffé, taking advantage of your suggestion, some tool for me to analyze the traffic of the application ?

  • Now considering the added code: doesn’t seem like a good idea, Rod. Not for performance reasons but for design reasons - this example uses exceptions to define application flow. Exceptions are not for this.

  • To moderators, the question is not duplicated, in fact, what is wrong is the question of the cited link, and in the answer of the quoted link ends up answering my question, but the question itself is not duplicated.

  • I agree, Rod: the answer to that question answers yours and the questions are different.

  • Rod and @Caffé As the answer there meets, the orientation is to close as duplicate (even though the questions are not identical).

Show 3 more comments

1 answer

-1

Yes, it has minimal runtime influence, unless you make large loops inside the Ry, use only when necessary and avoid using the Exception, use the exception according to the type of error expected to happen, example opening a connection with a bd use Sqlexception.

And regarding performance you prefer performance or avoid a crash?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.