I have two methods in which method 1 throw's an exception. Method 2 calls method 1 and if it throws exception it should be handled in method 2.
Here is my method 1
private Customer GetCustomer(string unformatedTaxId)
{
if (loan.GetCustomerByTaxId(new TaxId(unformatedTaxId)) == null)
{
throw new NotFoundException("Could not find the customer corresponding to the taxId '{0}' Applicant address will not be imported.", new TaxId(unformatedTaxId));
}
return loan.GetCustomerByTaxId(new TaxId(unformatedTaxId));
}
Now in the following method i am calling method 1
public void ProcessApplicantAddress(ApplicantAddress line)
{
try
{
Customer customer = GetCustomer(line.TaxId);
Address address = new Address();
address.AddressLine1 = line.StreetAddress;
address.City = line.City;
address.State = State.TryFindById<State>(line.State);
address.Zip = ZipPlusFour(line.Zip, line.ZipCodePlusFour);
}
catch(NotFoundException e)
{
eventListener.HandleEvent(Severity.Informational, line.GetType().Name, e.Message);
}
My problem is i am getting an unhandled exception, but i should catch it in the method 2. Please help me from this.
My NotFoundException Class
// class NotFoundException
public class NotFoundException : Exception
{
public NotFoundException() : base()
{
}
public NotFoundException(string message): base(message)
{
}
public NotFoundException(string format, params object[] args): base(string.Format(format, args))
{
}
public NotFoundException(string message, Exception innerException) : base(message, innerException)
{
}
public NotFoundException(string format, Exception innerException, params object[] args) : base(string.Format(format, args), innerException)
{
}
}