WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Handle Errors Including UDFs


Question:

I don't know why the error message is not suppressed by the intcontrol 73 in this script and why the code never go to the wberrorhandler label. very strange, i can't see it.
#DefineFunction copyfile(pathfrom, pathto, filename, newname)
IntControl(73, 2, 0, 0, 0)
If newname == "" Then newname = filename
If !FileExist(StrCat(pathto, newname))
If !DirExist(pathto) Then DirMake(pathto)
If StrSub(pathto, StrLen(pathto), 1) != "\" && StrSub(newname, 1, 1) != "\" Then pathto = StrCat(pathto, "\")
If StrSub(pathfrom, StrLen(pathfrom), 1) != "\" && StrSub(filename, 1, 1) != "\" Then pathfrom = StrCat(pathfrom, "\")
FileCopy(StrCat(pathfrom, filename), StrCat(pathto, newname), @false)
EndIf
Return
#EndFunction

IntControl(73, 2, 0, 0, 0)
retour = copyfile("c:\", "c:\test", "cdscdscv.doc", "*.bak")
Exit

:WBERRORHANDLER
erreur = LastError()
Select erreur
Case 1008
erreur = StrCat(erreur, " FileCopy: Failed")
Break
Case 1009
erreur = StrCat(erreur, " FileCopy: FROM file open failed")
Break
Case 1010
erreur = StrCat(erreur, " FileCopy: TO file open failed")
Break
Case 1011
erreur = StrCat(erreur, " FileCopy: I/O error")
Break
Case 0
Break
Case erreur
erreur = StrCat(erreur, " Autre erreur")
Break 
EndSelect
Message("", erreur)
IntControl(73, 2, 0, 0, 0)
Return

Answer:

The errorhandler for the function must be inside the function. :LABELS do not cross #DefineSubroutine or #DefineFunction boundries.

Question #2:

How do you handle your error messages? what is the best way to do something like i wish?

I need to suppress all error messages because i'm running those scripts "underground" via tivoli (just like a psexec command sent to a remote pc) and if there is a popup, the script just hangs and stay in the memory forever.

Usually i don't do a "message" on the error like in the example script i posted but i log it in a txt file on the local disk.

It's working great but it's the first time i try to run this with a definefunction.

Answer #2:

See IntControl 38 to write error to log file and exit...
Article ID:   W15980
File Created: 2004:03:30:15:42:06
Last Updated: 2004:03:30:15:42:06