Handing exception in BLL and return to client (either winforms or webforms)?

You can do several things; Focus on improving the user experience when an unexpected error presents itself. Always log errors either in eventlog or database. Implement sufficient infrastructure to not let exceptions happen unless they are system exceptions.

Use throw instread of throw exception Some links to help you: today.java.net/pub/a/today/2003/12/04/ex... onjava.com/pub/a/onjava/2003/11/19/excep... codeproject.com/KB/architecture/exceptio....

There are several ways to do it: 1) Throwing exceptions with describing message inside. 2) Firing events 3) Using special interfaces to interact with the user. For example you can implement something like IUiCallbacks interface and send the object, implementing this interface, to the BLL class or method.

Later, method in BLL can call IUiCallbacks.SendMessage() or IUiCallbacks.SendError() to notify presentation. And you can have different classes, such as WinFormsUiCallbacks, WebFormsUiCallbacks and SilentUiCallbacks, implementing this interface. I usually use 1) and 3) Example of 3) as requested: public interface IUiCallbacks { void SendMessage(string message); void SendException(string message, Exception ex); } public class WinFormsUiCallbacks : IUiCallbacks { public void SendMessage(string message) { MessageBox.

Show(message); } public void SendException(string message, Exception ex) { MessageBox. Show(string. Format("Unfortunately, the following errror has occurred:{0}{1}", Environment.

NewLine, ex. Message)); } } public class OrderService { private IUiCallbacks _iUiCallbacks; ... public OrderService() { ... } public OrderService(IUiCallbacks iUiCallbacks) { _iUiCallbacks = iUiCallbacks; } ... public void AddOrder(Order order) { ... if(OrderAlreadyExists(order)) { if(_iUiCallbacks! = null) _iUiCallbacks.

SendMessage("The order can not be added, because it is already accepted. "); return; } ... } ... } So it can be used like this: public partial class OrderForm : Form { ... public void btnAddOrderFromExcel_Click(...) { Order order = LoadOrderFromExcel(...); OrderService orderService = new OrderService(new WinFormsUiCallbacks()); orderService. AddOrder(order); } ... }.

. Yes very nice! I would look to hear more info on number3, when you say callback ie.

EVENT no? Do you have any example code? – Mark Smith Apr 29 '09 at 6:47 I added the example to my answer.

– nightcoder Apr 29 '09 at 10:47.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions