Answer the question
In order to leave comments, you need to log in
C# exception handling cost?
Following up on the C# question , what is the cost of type casting?
I met opinions that exception handling in C # slows down the application. Is it very noticeable in a real application?
Example in ASP NET Core
[HttpPut]
public IActionResult Update(SomeDto someDto)
{
Validate(someDto);
var result = DoBuissness(someDto);
return new OkObjectResult(result);
}
[HttpPut]
public IActionResult Update(SomeDto someDto)
{
var validationResult = Validate(someDto);
if(string.IsNullOrEmpty(validationResult ))
return new BadObjectResult(validationResult);
var result = DoBuissness(someDto);
return new OkObjectResult(result);
}
Answer the question
In order to leave comments, you need to log in
GENERATION of exceptions is not expensive. Therefore, the first and second pieces of +- code are comparable in speed.
Exception handling is expensive. There is a stack reversal, all sorts of shit ... For the processor - this is exactly the EXCEPTIONAL situation - there is no talk of any performance there - it's about maintaining efficiency.
But it is impossible to compare, because it is not clear what is there and how it is processed in the second fragment.
in the general case, it all comes down to the harmony of the error handling logic. maybe you should read this article
https://habr.com/ru/post/339606/
the author has a number of publications, including he writes quite actively about C#
https://habr.com/ru/users/marshinov/posts/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question