foreach (Exception objException in objExceptionsBE)
{
if (objException.Notifier == NotifierType.Error)
{
isSuccessFull = false;
lblErrMsg.Text = "This request has been failed. Please double check your criteria or contact technical support!";
}
if (objException.Notifier == NotifierType.Warning)
{
isSuccessFull = false;
lblErrMsg.Text = "This request has been failed. Please double check your criteria or contact technical support!";
}
}
if (isSuccessFull)
{
lblErrMsg.Text = "This request has been completed successfully!";
this.lblErrMsg.Style.Add("color", "#00C000");
}
public string Code
{
get { return _code.Trim(); }
set { _code = value.Trim(); }
}
public string Message
{
get { return _message.Trim(); }
set { _message = value.Trim(); }
}
public NotifierType Notifier
{
get { return _notifier; }
set { _notifier = value; }
}
}
public class ExceptionsBE : CollectionBase
{
public virtual ExceptionBE this[int index]
{
get { return (ExceptionBE)this.List[index]; }
set
{
if (value.GetType() == typeof(ExceptionBE))
{
this.List[index] = value;
}
}
}
suvo
Member
2 Points
254 Posts
exception handling
May 24, 2012 06:54 AM|LINK
I have found a goodway of exception handling
obj.MethodName(objpModel, ref objExceptionsBE);
foreach (Exception objException in objExceptionsBE)
{
if (objException.Notifier == NotifierType.Error)
{
isSuccessFull = false;
lblErrMsg.Text = "This request has been failed. Please double check your criteria or contact technical support!";
}
if (objException.Notifier == NotifierType.Warning)
{
isSuccessFull = false;
lblErrMsg.Text = "This request has been failed. Please double check your criteria or contact technical support!";
}
}
if (isSuccessFull)
{
lblErrMsg.Text = "This request has been completed successfully!";
this.lblErrMsg.Style.Add("color", "#00C000");
}
during dac execution
when success:
objExceptionsBE.Add(new ExceptionBE("", strMsg,Entity.BE.NotifierType.Success));
when failue
objExceptionsBE.Add(new Entity.BE.ExceptionBE("", ConfigurationSettings.AppSettings["Generic_Error_Message"].ToString(), Entity.BE.NotifierType.Error));
in web config
<add key="Generic_Error_Message" value="some error!"/>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Entity.BE
{
public class ExceptionBE
{
#region Private Variables
private NotifierType _notifier;
private string _code;
private string _message;
#endregion
public ExceptionBE()
{
this._code = string.Empty;
this._message = string.Empty;
this._notifier = NotifierType.Error;
}
public ExceptionBE(string code, string message, NotifierType notifier)
{
this._code = code;
this._message = message;
this._notifier = notifier;
}
public string Code
{
get { return _code.Trim(); }
set { _code = value.Trim(); }
}
public string Message
{
get { return _message.Trim(); }
set { _message = value.Trim(); }
}
public NotifierType Notifier
{
get { return _notifier; }
set { _notifier = value; }
}
}
public class ExceptionsBE : CollectionBase
{
public virtual ExceptionBE this[int index]
{
get { return (ExceptionBE)this.List[index]; }
set
{
if (value.GetType() == typeof(ExceptionBE))
{
this.List[index] = value;
}
}
}
public virtual void Add(ExceptionBE exceptionBE)
{
this.List.Add(exceptionBE);
}
}
public enum NotifierType
{
Success = 0,
Error = 1,
Warning = 2
}
}