Vahid
Vahid

Reputation: 5454

How to direct exceptions from Business layer to UI layer

In my user interface (UI) layer (WinForms/WPF), I am using a method from the business layer that accepts some input and creates an object that will be displayed in the UI. The code in the business layer may throw a general or specific exception, which will be handled and result in a null object being returned.

My question is, how can I pass error messages thrown in the business layer to the UI layer in a clean and efficient way? For example, if an exception is thrown in the business layer method, I want to get the error message and display it in the UI.

UI Layer

var configs = RuleConfigurations.CreateInstance(template, "C", "D");

Business Layer

  public static RuleConfigurations CreateInstance(string excelFileName, string fieldColName, string valueColName)
  {
     RuleConfigurations configs = null;
     try
     {
        configs = new RuleConfigurations(excelFileName, fieldColName, valueColName);
     }
     catch (DuplicateNameException e)
     {
        Console.WriteLine(e);
     }
     catch (Exception e)
     {
        Console.WriteLine(e);
     }

     return configs;
  }

Upvotes: 0

Views: 182

Answers (0)

Related Questions