samedi 6 février 2016

How can i throw exception to the value from app.config file

I was said to import sales tax rate from app.config file. In my app.config file i have two tax value GST and PST. How can i import this string value to my program code plus convert to decimal value and then add it . I have done till and i am receiving an error of throw exception. How can i throw exception ?? Thanks for the help in advance.

public decimal SalesTax 
        {
            get
            {
                decimal rateGST = Decimal.Parse(ConfigurationManager.AppSettings["rateGST"]);
                decimal ratePST = Decimal.Parse(ConfigurationManager.AppSettings["ratePST"]);
                return Subtotal * (rateGST + ratePST);
            }
        }

my App.config file is as below

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>

    <!--Government Sales Tax-->
    <add key ="rateGST" value="5"/>

    <!--Provincial Sales Tax-->
    <add key="ratePST" value="8"/>

  </appSettings>
</configuration>

Aucun commentaire:

Enregistrer un commentaire