Skip to content

Instantly share code, notes, and snippets.

@jewer
Created April 17, 2012 22:54
Show Gist options
  • Select an option

  • Save jewer/2409658 to your computer and use it in GitHub Desktop.

Select an option

Save jewer/2409658 to your computer and use it in GitHub Desktop.
What's wrong with this code?
public class TaxCalculationException : ApplicationException
{
private string _zipCode;
public TaxCalculationException(string zipCode, Exception ex)
: base("An error occurred while processing tax.", ex)
{
_zipCode = zipCode;
}
}
public class MyCustomApplicationException : ApplicationException
{
public string ProblemDetails { get; set; }
}
class Program
{
static void Main(string[] args)
{
const double basePrice = 100.00d;
const string zipCode = "55116";
var totalPrice = CalculateTaxDue(basePrice, zipCode);
Console.Write("Your purchase for {0} dollars in zipcode {1} costs {2}", 100, "55116", totalPrice);
}
public static double CalculateTaxDue(double purchasePrice, string zipCode)
{
var totalPrice = 0;
try
{
var stateTax = new StateTaxCalculator(zipCode).Calculate(purchasePrice);
var cityTax = new CityTaxCalculator(zipCode).Calculate(purchasePrice);
return purchasePrice + stateTax + cityTax;
}
catch (NullReferenceException ex)
{
throw new TaxCalculationException(zipCode, ex);
}
catch (ApplicationException aex)
{
throw aex;
}
catch (ArgumentException)
{
LogFailureToCalculateTaxDue(purchasePrice, zipCode);
}
catch (NotSupportedException ex)
{
LogExceptionInformation(ex);
throw new TaxCalculationException(zipCode, ex);
}
catch (MyCustomApplicationException ex)
{
EmailProblemDetailsToTechSupport(ex.ProblemDetails);
throw ex;
}
return totalPrice;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment