Created
April 17, 2012 22:54
-
-
Save jewer/2409658 to your computer and use it in GitHub Desktop.
What's wrong with this code?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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