Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Class Design Question
Message
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
01054128
Message ID:
01054189
Views:
21
>I asked my question wrong.
>
>I have a process that goes thru various methods until I reach a point
>where I'm updating a record.
>
>I know the record should be there, but I test for it just in case.
>
>If the record is not there, what do you do at this point? You're already
>4 levels deep, and theres no reason to cancel, but you want to notify the
>user and recover gracefully.
>
>A TRY/CATCH in the 1st method won't solve this scenerio.
>
Here is what I use:

My class CustomError Method:
*---------------------- Location Section ------------------------
*   Library: 	Aqueueprocess.vcx
*   Class: 		Assignqueues
*   Method: 	Customerror()
*----------------------- Usage Section --------------------------
*)  Description:
*)

*   Scope:      Public
*   Parameters:
*$  Usage:
*$
*   Returns:
*--------------------- Maintenance Section ----------------------
*   Change Log:
*       CREATED 	06/01/2005 - NN
*		MODIFIED
*----------------------------------------------------------------
lparameters toErr
if vartype(m.toErr) = "O" && real exception occurred
	if m.toErr.ErrorNo <> 1098 && Custom error
		local lcError, lnI, laErrors[1]
		lcError = "Encountered an error #" + transform(m.toErr.ErrorNo) + " " + ;
			m.toErr.message + " in method " + m.toErr.LineContents + ;
			" on line # " + transform(m.toErr.lineno) + chr(13)

		if not inlist(type('gaErrors[1]'),"U", "L")

			for lnI = 1 to alen(gaErrors)
				lcError = m.lcError + transform(gaErrors [m.lnI]) + chr(13)
			next
		endif

		this.lRealError = .t.
		this.cError = m.lcError
	endif
endif

local lnTrxnLevel
lnTrxnLevel = txnlevel( )
do while m.lnTrxnLevel > 0
	rollback
	lnTrxnLevel = txnlevel( )
enddo
My top level method has:
local loErr
set talk off
set deleted on && Very important, otherwise we can pick up deleted records by mistake
=aused(this.arrOriginallyUsed)

with this
	try
		.CreateLogfile()

** We want to have a clear log of everything
		.WriteToLogFile("Started to run assigning queues process")

		.lRunUpdates = m.tlUpdateForms
		if .lRunUpdates
			local lcSubject
			lcSubject = 'TransEmployeesQueueSubject'
			this.oSubject = createobject(m.lcSubject) && Create "INVESTIGATOR" subject object
		ENDIF
		
		.OpenQueueTables() && Opens queue related tables with buffering
		
		.SetDepartment(m.tcDepartment_Code)

		.SetNumberOfDays(m.tnNumberOfDays)

		.SetQueueNameFrom(m.tcQueue_Name_From)

		.SetQueueNameTo(m.tcQueue_Name_To)

		.GetUsers(m.tcUser)

		.GetProfiles()

		.GetAlreadyScheduled()

		for lnI = 1 to .nNumberOfDays

			ldScheduled_Date = ttod(.arrQDates[m.lnI])

			select c_Users
			go top && Very important !

			scan
				.Assign_Accounts_To_User( ;
					.cQueue_Name_To, c_Users.cDepartment_Code, ;
					c_Users.cUserID, c_Users.iUserID, ;
					m.ldScheduled_Date)
				if .lRunUpdates
					.OnStateChange("SAVE")
				endif
			endscan
		next

		.WriteToLogFile("Finished to run assigning queues process")

	catch to loErr
		.CustomError(m.loErr)
	finally
		release loErr
		.CleanUp()
	endtry

endwith

return
And if I want to raise custom error I do:
* This account is already scheduled - should not happen
		this.cError = "The account " + ;
			m.lcTrans_Employees_Queues_pk + " is already scheduled!"
*---------------------- Location Section ------------------------
*   Library: 	Aqueueprocess.vcx
*   Class: 		Assignqueues  
*   Method: 	Cerror_assign() 
*----------------------- Usage Section --------------------------
*)  Description: 
*)

*   Scope:      Public
*   Parameters: 
*$  Usage:      
*$              
*   Returns:  
*--------------------- Maintenance Section ----------------------
*   Change Log:
*       CREATED 	06/01/2005 - NN 
*		MODIFIED
*----------------------------------------------------------------
LPARAMETERS vNewVal
*To do: Modify this routine for the Assign method
THIS.cError = m.vNewVal
this.WriteToLogfile(this.cError)
IF NOT this.lRealError
   ERROR this.cError && Trigger an error
endif   
this.lRealError = .f.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform