Public Class DALException
Inherits ApplicationException
Const PERMIT_LOGGING As Boolean = False
Public Enum DALExceptionCode
Concurrency
ConnectionFailure
DatabaseFailure
LoginFailure
Constraint
Transaction
Locks
General
End Enum
Private m_ExceptionCode As DALExceptionCode = DALExceptionCode.General
Private m_DataSet As DataSet
Private m_ErrorRows As DataRow()
Private m_Log As New StringBuilder()
Public Sub New(ByVal msg As String, ByVal exc As Exception, ByVal ds As DataSet)
'Set the default message and inner exception
MyBase.New(msg, exc)
m_DataSet = ds
'determine what type of exception we have
If TypeOf exc Is ConstraintException Then 'thrown by the DataSet
m_Log.Append("ConstraintException occured" & vbCrLf)
m_ExceptionCode = DALExceptionCode.Constraint
ElseIf TypeOf exc Is DBConcurrencyException Then
m_Log.Append("DBConcurrencyException occured" & vbCrLf)
m_ExceptionCode = DALExceptionCode.Concurrency
ElseIf TypeOf exc Is SqlClient.SqlException Then
m_Log.Append("SqlClient.SqlException occured" & vbCrLf)
processSQLException(exc)
ElseIf TypeOf exc Is DataException Then
'this should handle all other providers - OLEDB, ODBC
m_Log.Append("DataException occured" & vbCrLf)
ElseIf TypeOf exc Is Exception Then
'anything left
m_Log.Append("Exception occured" & vbCrLf)
m_ExceptionCode = DALExceptionCode.General
End If
detectRowErrors(ds)
m_Log.Append("Original Exception: " & vbCrLf)
m_Log.Append(exc.ToString)
logException(m_Log.ToString)
End Sub
=====================================================
My questions
==============================================
1. What I can find from the above code is that it has centralized all the Exception Types under a User Defined Exception.
I know it is centralized in a certain manner and maintenance of codes would be easier.
Is it a good practice?