Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 rsolanki 1
<%
2
'=============================================================
3
'//
4
'//						Exception Handler
5
'//
6
'// version: 		1.4
7
'//	last modified: 	20-Jul-2004 14:17 by Sasha Vukovic
8
'=============================================================
9
%>
10
<%
11
'------------- GLOBALS --------------
12
Const enumEXCEPTION_HANDLER_SESSION = "DM_EXCEPTION_HANDLER"
13
'------------------------------------
14
%>
15
<%
16
Class ExceptionHandler
17
 
18
	Private sMsgSummary
19
	Private sMsgDetails
20
	Private bIsDisplayed
21
	Private bErrorRedirect
22
 
23
	Private SEPARATOR
24
 
25
	Public Property Let ErrorRedirect ( bVal )
26
		bErrorRedirect = bVal
27
		Session( enumEXCEPTION_HANDLER_SESSION ) = NULL  ' Clear message session variable
28
	End Property
29
 
30
	Public Property Get MessageSummary
31
		MessageSummary = sMsgSummary
32
		bIsDisplayed = TRUE
33
	End Property
34
 
35
	Public Property Get MessageDetails
36
		MessageDetails = sMsgDetails
37
		bIsDisplayed = TRUE
38
	End Property
39
 
40
	'-----------------------------------------------------------------------------------------------------------------
41
	Public Sub LogAction ( nUserId, nEvent, sMethod, sActionScript, sDescription, ByRef OraDatabase )
42
		OraDatabase.ExecuteSQL _
43
		"BEGIN   pk_Utils.Log_Action ( "&_
44
			nUserId &","&_
45
			nEvent &","&_
46
			"'"& sMethod &"',"&_
47
			"'"& sActionScript &"',"&_
48
			"'"& sDescription &"'"&_
49
			"  ); "&_
50
		"END;"
51
	End Sub
52
	'-----------------------------------------------------------------------------------------------------------------
53
	Public Function Finally ()
54
		If IsNull( sMsgSummary ) OR bErrorRedirect Then
55
			Finally = TRUE
56
		Else
57
			Finally = FALSE
58
		End If
59
	End Function
60
	'-----------------------------------------------------------------------------------------------------------------
61
	Public Sub Try ()
62
		Err.Clear
63
	End Sub
64
	'-----------------------------------------------------------------------------------------------------------------
65
	Public Sub Catch ()
66
 
67
		If Err.Number <> 0 Then
68
 
69
			If IsNull( sMsgSummary ) Then
70
				sMsgSummary = Err.Source
71
				sMsgDetails = Err.Description
72
			End If
73
 
74
			' Redirect to Message
75
			If bErrorRedirect Then
76
				Session( enumEXCEPTION_HANDLER_SESSION ) = sMsgSummary & SEPARATOR & sMsgDetails
77
				Call OpenInWindow ( "messages/msgPleaseNote.asp" )
78
				bIsDisplayed = TRUE
79
			End If
80
 
81
		End If
82
 
83
		Err.Clear
84
	End Sub
85
	'-----------------------------------------------------------------------------------------------------------------
86
	Public Sub TryORA ( ByRef objOraSession )
87
		Err.Clear
88
		' Begin DB transaction
89
		objOraSession.BeginTrans
90
 
91
	End Sub
92
	'-----------------------------------------------------------------------------------------------------------------
93
	Public Sub CatchORA ( ByRef objOraSession )
94
		If Err.Number <> 0 Then
95
 
96
			If IsNull( sMsgSummary ) Then
97
				sMsgSummary = GetORAErrDescription ( Err.Description )
98
				sMsgDetails = Err.Description
99
			End If
100
 
101
			' Roll back DB transaction
102
			objOraSession.RollBack
103
 
104
 
105
			' Redirect to Message
106
			If bErrorRedirect Then
107
				Session( enumEXCEPTION_HANDLER_SESSION ) = sMsgSummary & SEPARATOR & sMsgDetails
108
				Call OpenInWindow ( "messages/msgPleaseNote.asp" )
109
				bIsDisplayed = TRUE
110
			End If
111
 
112
		Else
113
			' Commit db transaction
114
			objOraSession.CommitTrans
115
 
116
		End If
117
 
118
		Err.Clear
119
	End Sub
120
	'-----------------------------------------------------------------------------------------------------------------
121
	Private Function GetORAErrDescription ( sErrMsg )
122
		Dim tempArr, endOfMsg
123
 
124
		' Example of ORAErr Description
125
		' SQL execution error, ORA-20000: Duplicate Network Node name. ORA-06512: at "DM_DEV.PK_NETWORK_NODE", line 20 ORA-06512: at line 1
126
 
127
		tempArr = Split ( sErrMsg, ":" )		' Oracle error message is split with :
128
 
129
		endOfMsg = InStr( tempArr(1), "ORA" )
130
 
131
		If endOfMsg > 0 Then
132
			GetORAErrDescription = Left( tempArr(1), endOfMsg - 1 )
133
 
134
		Else
135
			GetORAErrDescription = tempArr(1)
136
 
137
		End If
138
 
139
 
140
	End Function
141
	'-----------------------------------------------------------------------------------------------------------------
142
	Public Sub DisplayMessage ()
143
		Dim msgTemplate
144
		msgTemplate = ReadFile( APP_ROOT &"\scripts\note_style.html" )
145
		msgTemplate = Replace( msgTemplate, "%WIDTH%", "100%" )
146
		msgTemplate = Replace( msgTemplate, "%IMAGE%", "s_warning.gif" )
147
		msgTemplate = Replace( msgTemplate, "%DIV_NAME%", "DIV_MESSAGE" )
148
		msgTemplate = Replace( msgTemplate, "%NOTE%", sMsgSummary )
149
		msgTemplate = Replace( msgTemplate, "%MESSAGE_DETAILS%", sMsgDetails )
150
 
151
		Response.write msgTemplate
152
		bIsDisplayed = TRUE
153
	End Sub
154
	'-----------------------------------------------------------------------------------------------------------------
155
	Private Sub GetSessionMessages ()
156
		Dim tempArr
157
		If Session( enumEXCEPTION_HANDLER_SESSION ) <> "" OR NOT IsNull(Session( enumEXCEPTION_HANDLER_SESSION )) Then
158
			tempArr = Split ( Session( enumEXCEPTION_HANDLER_SESSION ), SEPARATOR )
159
			If UBound( tempArr ) > 0 Then
160
				sMsgSummary = tempArr(0)
161
				sMsgDetails = tempArr(1)
162
			End If
163
 
164
			Session( enumEXCEPTION_HANDLER_SESSION ) = NULL
165
 
166
		End If
167
	End Sub
168
	'-----------------------------------------------------------------------------------------------------------------
169
	Private Sub Class_Initialize()
170
		'// Perform action on creation of object. e.g. Set myObj = New ThisClassName
171
		SEPARATOR = "|SEPARATOR|"
172
 
173
		sMsgSummary = NULL
174
		bIsDisplayed = FALSE
175
		bErrorRedirect = TRUE		' By Default On error redirect to error message page
176
 
177
		Call GetSessionMessages ()
178
	End Sub
179
	'-----------------------------------------------------------------------------------------------------------------
180
	Private Sub Class_Terminate()
181
		'// Perform action on object disposal. e.g. Set myObj = Nothing
182
		If NOT bIsDisplayed AND NOT IsNull(sMsgSummary) Then
183
			Response.write ( sMsgSummary & "<br>" & sMsgDetails )
184
		End If
185
	End Sub
186
	'-----------------------------------------------------------------------------------------------------------------
187
End Class
188
%>