 |
 |
|
|
|
Error Handling
The following example uses the Data Provider as an example to illustrate
how errors are handled by the foundation classes. The same rules can
be applied to other foundation classes. The Data Provider supplies
data for the various controller ASPX Pages. When an error occurs, the
Data Provider either recovers from the error or it passes the error to the ASPX Page.
Caution:
The Data Provider should never attempt to display the error in any manner.
Display of the error message must strictly be handled by the ASPX Page
controller.
- The Data Provider uses the dedicated Foundation Class, FnDPException,
to throw exceptions. This class is defined in ..\Program Files\FnOpenClient\Util\FnError.vb.
- The Data Provider must define the error code name for each error and
add it to the FN_ERR_DP enumerator type. The “Fn_ERR_DP_” suffix must
be appended to each error code name to allow the error message key to
be generated for each error code. The localized error messages must
then be added to the resource file.
- The Data Provider must add code to its helper function to retrieve
the localized string. For example:
Public Function DPError(ByVal ErrorCode As Long, ByVal e As
Exception) As FnDPException
Dim msg As String
Dim aDPExcep as FnDPException
Select Case ErrorCode
Case FN_ERR_DP.FailedToGetStepElement
msg = rm.GetResourceString("FN_ERR_DP_ FailedToGetStepElement")
Case FN_ERR_DP.NoPrefetchedStepElement
msg = rm.GetResourceString("FN_ERR_DP_NoPrefetchedStepElement")...
Case Else
msg = rm.GetResourceString("FN_ERR_UnknownError")
End Select
If e Is Nothing Then
aDPExcep = New FnDPException(msg)
Else
aDPExcep = New FnDPException(msg,
e)
End If
aDPExcep.FnErrorCode = ErrorCode
Return aDPExcep
End Function
Public Function DPError(ByVal ErrorCode As Long) As FnDPException
Return DPError(ErrorCode, Nothing)
End Function
|