public ExceptionList(ExceptionAction defaultExceptionAction) { exceptionArray = new ExceptionCell[1]; exceptionArray[0] = new ExceptionCell { ExceptionType = typeof(Exception), ExceptionAction = defaultExceptionAction }; }
public void Add(Type exceptionType, ExceptionAction exceptionAction) { ExceptionCell[] newExceptionArray; if (exceptionArray.Length > 0) { foreach (var exception_for in exceptionArray) { if (exceptionType == exception_for.ExceptionType) { throw new ExceptionListException("This type of exception already in the exception list"); } } newExceptionArray = new ExceptionCell[exceptionArray.Length + 1]; for (int i = 0; i < exceptionArray.Length; i++) { newExceptionArray[i] = exceptionArray[i]; } newExceptionArray[exceptionArray.Length] = new ExceptionCell(exceptionType, exceptionAction); exceptionArray = newExceptionArray; return; } newExceptionArray = new ExceptionCell[1]; newExceptionArray[0] = new ExceptionCell(exceptionType, exceptionAction); exceptionArray = newExceptionArray; }
public bool Remove(Type exceptionType) { if (exceptionArray.Length > 1) { for (int i = 0; i < exceptionArray.Length; i++) { if (exceptionType == exceptionArray[i].ExceptionType) { ExceptionCell[] newExceptionArray = new ExceptionCell[exceptionArray.Length - 1]; for (int j = 0, k = 0; j < exceptionArray.Length; j++, k++) { if (j != i) { if (k != exceptionArray.Length - 1) { newExceptionArray[k] = exceptionArray[j]; } exceptionArray = newExceptionArray; return(true); } } } } } else if (exceptionArray.Length == 1) { if (exceptionType == exceptionArray[0].ExceptionType) { throw new ExceptionListException("You can not remove a default exception"); } } return(false); }