Exception Handling Impact on Service (API) Response Time

I’ve encountered an issue where calling a service or DEE that generates an exception results in significantly slower response times compared to the same request without throwing an exception.

Has anyone else experienced this? What could be causing the delay, and are there any best practices for optimizing exception handling to improve response times?

Looking forward to your insights and suggestions!

Hi Irina,

By itself, exceptions in C# already have a performance cost, but in general that cost should not be a “significantly slower response”.
On thing that may be happening is, because every API call in our system has its own transaction, and when an exceptions happen the transaction is rolled back, meaning that every data change in data in the Database is then reverted, if the API that you are calling touches many records in the Database, the rollback after an exception may take a little time.

But this is just one possible cause, my recommendation is for you to investigate further what point in the code takes time after the exception happens.

Best regards,

Rodrigo Paiva

Thanks Rodrigo, Is there a way to trigger an exception without rolling back the transactions ?

Luís Ponte wrote:

No, exceptions will always force you to rollback the transaction in our framework. There are some edge cases where this may be possible (for example, if you are catching an exception when writing to a file, for example), but as a general guideline, you should assume that your transaction should be rolled back whenever an exception occurs.