title: How to handle a NullReference Exception c#
body: <p>I am trying to handle a NullReference Exception, but i am confused how to handle that. Here is my sample code where a NullReference exception is raised:</p>
  
  <pre><code> private Customer GetCustomer(string unformatedTaxId)
          {               
                  return loan.GetCustomerByTaxId(new TaxId(unformatedTaxId));                
          }
  </code></pre>
  
  <p>Now i am handling this in the following method</p>
  
  <pre><code> public void ProcessApplicantAddress(ApplicantAddress line)
          {
              try
              {
                  Customer customer = GetCustomer(line.TaxId);
                  //if (customer == null)
                  //{
                  //    eventListener.HandleEvent(Severity.Informational, line.GetType().Name, String.Format("Could not find the customer corresponding to the taxId '{0}' Applicant address will not be imported.", new TaxId(line.TaxId).Masked));
                  //    return;
                  //}
                  Address address = new Address();
                  address.AddressLine1 = line.StreetAddress;
                  address.City = line.City;
                  address.State = State.TryFindById&lt;State&gt;(line.State);
                  address.Zip = ZipPlusFour(line.Zip, line.ZipCodePlusFour);
                  }
              catch(NullReferenceException e)
              {
                  //eventListener.HandleEvent(Severity.Informational, line.GetType().Name, String.Format("Could not find the customer corresponding to the taxId '{0}' Applicant address will not be imported.", new TaxId(line.TaxId).Masked));
                  eventListener.HandleEvent(Severity.Informational, line.GetType().Name, e.Message);
              }
          }
  </code></pre>
  
  <p>I the previous case i am writing like if(customer == null) now i should get rid of that code so that i can handle it in the catch block.</p>
  
  <p>Please help me how to throw that exception.</p>