Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm unsure of your specific requirements, but it seems like <em>plain dll</em> is a standard business logic library. Based on my experience, I'd suggest leaving the business logic as implementation agnostic as possible (within reason, of course) as you'll likely be handling the exceptions differently anyway. By throwing different exceptions based on the implementation, you'll be mixing the responsiblities of the business logic with those of the implementor.</p> <p>My suggestion would be to throw a common set of exceptions from the business logic library, and catch/handle them differently for each implementation. E.g. a console application may just ask for the input again, where as a WCF application may throw a fault exception.</p> <p>Take the following code as example:</p> <pre><code>// Simple business logic that throws common exceptions namespace BusinessLogicLibrary { public class Math { public static int Divide(int dividend, int divisor) { if (divisor == 0) throw new DivideByZeroException(); return dividend / divisor; } } } // WCF calls to business logic and handles the exception differently namespace WcfProject { [ServiceContract] public interface IService { [OperationContract] int Divide(int dividend, int divisor); } public class Service : IService { public int Divide(int dividend, int divisor) { try { return BusinessLogicLibrary.Math.Divide(dividend, divisor); } catch (Exception ex) { throw new FaultException( new FaultReason(ex.Message), new FaultCode("Division Error")); } } } } // Console application calls library directly and handles the exception differently namespace ConsoleApplication { class Program { static void Main(string[] args) { ShowDivide(); } static void ShowDivide() { try { Console.WriteLine("Enter the dividend: "); int dividend = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the divisor: "); int divisor = int.Parse(Console.ReadLine()); int result = BusinessLogicLibrary.Math.Divide(dividend, divisor); Console.WriteLine("Result: {0}", result); } catch (DivideByZeroException) { // error occurred but we can ask the user again Console.WriteLine("Cannot divide by zero. Please retry."); ShowDivide(); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload