Tuesday, June 16, 2009

Product vs Core. Why use low level API ?

Sometimes I wish that product API would not raise errors, but just return numeric result with the error number. This is what happening in the core API.

For example, the W6PTimeIntervals is a simple product wrapper for the W6TimeIntervals core class. Interesting is the fact that W6TimeInterval is a core class, which is used in the product without a wrapper.

However, the following short example of code is an implementation of a method, which is sometimes needed when dealing with time intervals. The error handling is general and there is no need to deal with "end of list" error:
Private Sub UnSetTimeIntervals( _
ByVal intervals As W6PTimeIntervals, _
ByVal unset As W6PTimeIntervals)

Try
Dim W6RC_MDL_TIME_INTERVALS_END_OF_LIST _
As Integer = 4120

Dim rc As Integer = 0

Dim timeInterval As W6TimeInterval
= New W6TimeInterval

' UnSet older intervals from the newer intervals,
' so only the new interval remains
rc = unset.RefW6TimeIntervals.GetFirst( _
timeInterval)

Do While (CatchRcExclude(rc, _
W6RC_MDL_TIME_INTERVALS_END_OF_LIST))

CatchRC( _
intervals.RefW6TimeIntervals.UnSetTimeInterval _
(timeInterval))

rc = unset.RefW6TimeIntervals.GetNext( _
timeInterval)

Loop

Catch ex As Exception
Call GeneralErrorHandling("UnSetTimeIntervals")
End Try
End Sub

Private Function CatchRcExclude( _
ByVal rc As Integer, _
ByVal exclude As Integer) As Boolean

If (rc = exclude) Then Return False
CatchRC(rc)

Return True
End Function

Private Sub CatchRC(ByVal rc As Integer)

If (rc = 0) Then Exit Sub

Dim errObject As W6ShPError = _
W6ShPErrorUtilities.W6CreateCoreError( _
rc, "", True, True)
End Sub

No comments:

Post a Comment

Please keep comments clean at the ClickDev blog.

 
HTML Hit Counter