Max_dev
Max_dev

Reputation: 508

Retry on Temporary exceptions .Net

Recently i have created some batch program(console) where the system will fetch records from the database, create some pdf and send them to the destination via mail. I got some requirement now like system should retry for few times if there are any exception.

I am sure retrying all exception's will not help because some exception will occure due to business logics. Only temporary exceptions should be handled. But my question is how to identify those temporary exceptions in the .net library?

In my case possibile temporary exception which i may get will be due to any one of the following

  1. Sql server

  2. Smpt server

  3. Pdf creation.

Among the above how to identity the exact exception type?

Can anyone help me on this?

Upvotes: 2

Views: 97

Answers (1)

usr
usr

Reputation: 171178

There is no built-in way to identify transient errors based on the exception object. You have to find out from documentation and through testing what typical transient faults can happen.

For example SQL errors can be transient (timeout, network, deadlock, ...) or permanent (row failed to insert because of invalid data).

There's no better way to do this than to manually build a list. Be sure to be specific in your conditions, for example use SqlException.Number to whitelist the exact errors you want to deal with.

Entity Framework has some support for transient errors. Look into the source code to see how they do it. Even they are using the approach I suggest which I found out by looking at the source code commits they make. They gradually add more and more errors which they initially forgot.

Upvotes: 2

Related Questions