c# - Throwing business exceptions -


to invoke external services such payment gateways create provider assembly such as: mycompany.providers.braintree, encapsulates logic related making service invocation. works pass through , contained in own assembly.

let's provider has "dopayment" method invokes service on gateway returns couple of status body message:

  • code 111 -> payment successfully
  • code 222 -> not enough funds
  • code 333 -> unknown payee

should provider throw "business" exception when payment has not completed successfully, or should service return type wraps gateway returned?

i have opted out not throwing exceptions in these kind of situations because not ab exception case - gateway processed request (the request processed thought payment not completed) process microsoft's recommendation well:

creating , throwing exceptions (c# programming guide)

exceptions should not used change flow of program part of ordinary execution. exceptions should used report , handle error conditions.

martin fowler has opinions on matter, replacing throwing exceptions notification in validations

exceptions signal outside expected bounds of behavior of code in question

but it's related input validation.

what guys do?


Comments