EkBanda
EkBanda

Reputation: 65

C#, async function chain, where to handle exception

I think it is more of a style question, just trying to find out the best way there is.

I have the following scenario...

  1. DB function executing in async mode (for data fetching task.run with data-adapter and for non query using async functions provided by ado.net).

  2. DB function (data fetching) result is passed to helper functions which create object lists for fetched data.

  3. The UI, which consumes the object lists returned by helper functions.

UI also passes down task cancellation token to helper functions -> db functions, so that async tasks can be cancelled at the time of UI close.

Now, any exception thrown by DB function can be handled at all 3 points namely at DB function level, helper function level and UI level. But what should be the best location to handle it (including task cancellation exception).

Upvotes: 0

Views: 174

Answers (1)

VidasV
VidasV

Reputation: 4895

Consumer should be handling exceptions in this case the UI. You can handle in the middle layers but throw a new one just to make it easier to comprehend for the UI and provide meaningful messages to end user

Upvotes: 2

Related Questions