<% '============================================================= '// '// Exception Handler '// '// version: 1.4 '// last modified: 20-Jul-2004 14:17 by Sasha Vukovic '============================================================= %> <% '------------- GLOBALS -------------- Const enumEXCEPTION_HANDLER_SESSION = "DM_EXCEPTION_HANDLER" '------------------------------------ %> <% Class ExceptionHandler Private sMsgSummary Private sMsgDetails Private bIsDisplayed Private bErrorRedirect Private bLastOraFailed Private SEPARATOR Public Property Let ErrorRedirect ( bVal ) bErrorRedirect = bVal Session( enumEXCEPTION_HANDLER_SESSION ) = NULL ' Clear message session variable End Property Public Property Get MessageSummary MessageSummary = sMsgSummary bIsDisplayed = TRUE End Property Public Property Get MessageDetails MessageDetails = sMsgDetails bIsDisplayed = TRUE End Property Public Property Get LastOraFailed LastOraFailed = bLastOraFailed End Property '----------------------------------------------------------------------------------------------------------------- 'Public Sub LogAction ( nUserId, nEvent, sMethod, sActionScript, sDescription, ByRef OraDatabase ) ' OraDatabase.ExecuteSQL _ ' "BEGIN pk_Utils.Log_Action ( "&_ ' nUserId &","&_ ' nEvent &","&_ ' "'"& sMethod &"',"&_ ' "'"& sActionScript &"',"&_ ' "'"& sDescription &"'"&_ ' " ); "&_ ' "END;" 'End Sub '----------------------------------------------------------------------------------------------------------------- Public Function Finally () If IsNull( sMsgSummary ) OR bErrorRedirect Then Finally = TRUE Else Finally = FALSE End If End Function '----------------------------------------------------------------------------------------------------------------- Public Sub Try () Err.Clear End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub Catch () If Err.Number <> 0 Then If IsNull( sMsgSummary ) Then sMsgSummary = Err.Source sMsgDetails = Err.Description End If ' Redirect to Message If bErrorRedirect Then Session( enumEXCEPTION_HANDLER_SESSION ) = sMsgSummary & SEPARATOR & sMsgDetails Call OpenInWindow ( "messages/msgPleaseNote.asp" ) bIsDisplayed = TRUE End If End If Err.Clear End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub TryORA ( ByRef objOraSession ) Err.Clear bLastOraFailed = FALSE ' Begin DB transaction objOraSession.BeginTrans End Sub '----------------------------------------------------------------------------------------------------------------- Public Sub CatchORA ( ByRef objOraSession ) If Err.Number <> 0 Then bLastOraFailed = TRUE If IsNull( sMsgSummary ) Then sMsgSummary = GetORAErrDescription ( Err.Description ) sMsgDetails = Err.Description End If ' Roll back DB transaction objOraSession.RollBack ' Redirect to Message If bErrorRedirect Then Session( enumEXCEPTION_HANDLER_SESSION ) = sMsgSummary & SEPARATOR & sMsgDetails Call OpenInWindow ( "messages/msgPleaseNote.asp" ) bIsDisplayed = TRUE End If Else bLastOraFailed = FALSE ' Commit db transaction objOraSession.CommitTrans End If Err.Clear End Sub '----------------------------------------------------------------------------------------------------------------- Private Function GetORAErrDescription ( sErrMsg ) Dim tempArr, endOfMsg ' Example of ORAErr Description ' SQL execution error, ORA-20000: Duplicate Network Node name. ORA-06512: at "DM_DEV.PK_NETWORK_NODE", line 20 ORA-06512: at line 1 tempArr = Split ( sErrMsg, ":" ) ' Oracle error message is split with : endOfMsg = InStr( tempArr(1), "ORA" ) If endOfMsg > 0 Then GetORAErrDescription = Left( tempArr(1), endOfMsg - 1 ) Else GetORAErrDescription = tempArr(1) End If End Function '----------------------------------------------------------------------------------------------------------------- Public Sub DisplayMessage () Dim msgTemplate msgTemplate = ReadFile( APP_ROOT &"\scripts\note_style.html" ) msgTemplate = Replace( msgTemplate, "%WIDTH%", "100%" ) msgTemplate = Replace( msgTemplate, "%IMAGE%", "s_warning.gif" ) msgTemplate = Replace( msgTemplate, "%DIV_NAME%", "DIV_MESSAGE" ) msgTemplate = Replace( msgTemplate, "%NOTE%", sMsgSummary ) msgTemplate = Replace( msgTemplate, "%MESSAGE_DETAILS%", sMsgDetails ) Response.write msgTemplate bIsDisplayed = TRUE End Sub '----------------------------------------------------------------------------------------------------------------- Private Sub GetSessionMessages () Dim tempArr If Session( enumEXCEPTION_HANDLER_SESSION ) <> "" OR NOT IsNull(Session( enumEXCEPTION_HANDLER_SESSION )) Then tempArr = Split ( Session( enumEXCEPTION_HANDLER_SESSION ), SEPARATOR ) If UBound( tempArr ) > 0 Then sMsgSummary = tempArr(0) sMsgDetails = tempArr(1) End If Session( enumEXCEPTION_HANDLER_SESSION ) = NULL End If End Sub '----------------------------------------------------------------------------------------------------------------- Private Sub Class_Initialize() '// Perform action on creation of object. e.g. Set myObj = New ThisClassName SEPARATOR = "|SEPARATOR|" sMsgSummary = NULL bIsDisplayed = FALSE bErrorRedirect = TRUE ' By Default On error redirect to error message page bLastOraFailed = FALSE Call GetSessionMessages () End Sub '----------------------------------------------------------------------------------------------------------------- Private Sub Class_Terminate() '// Perform action on object disposal. e.g. Set myObj = Nothing If NOT bIsDisplayed AND NOT IsNull(sMsgSummary) Then Response.write ( sMsgSummary & "
" & sMsgDetails ) End If End Sub '----------------------------------------------------------------------------------------------------------------- End Class %>