 |
SoftTree Technologies
Technical Support Forums
|
|
Author |
Message |
Jason Hoskins
Joined: 12 Mar 2004 Posts: 68
|
|
GetLastError Problem |
|
I am trying to use GetLastError, ideally on the "On Error" section of the job. I cannot get the meesage returned even when using the this method or running the sample code within the help. The message variable is always "". It appears the notification script is run before the error is logged. How do I get around this even if it is within the main script code?
|
|
Wed Sep 17, 2008 1:15 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7949
|
|
|
|
I assume you want to get last error occurred during the job execution. I don't think GetLastError will work in a notification action because the scope of the "last error" is limited to the job and notification action is something that the queue executes in response to job events. When called fro ma notification action it returns last error occurred in that notification action. In other words, this method returns last error occurred in the scope of the "current" script, meaning in that particular script or in user defined functions called from that particular script. Hope this description makes sense.
|
|
Wed Sep 17, 2008 2:03 pm |
|
 |
Jason Hoskins
Joined: 12 Mar 2004 Posts: 68
|
|
|
|
It does make sense but even your example is not returning a message. The file does not exist, it enters the error handling but the GetLastError is empty.
[code]
// setup error handling
OnErrorGoTo NOTIFY_ADMIN
// attempt to delete the file
FileDelete( "c:\\data\\accounts.old" )
NORMAL:
// ... continue normal processing here ...
Exit
NOTIFY_ADMIN:
Dim message, string
// get error message
GetLastError message
Concat "File c:\\data\\accounts.old cannot be deleted. Error: ", message, message
// notify Administrator
messagebox ( message )
// ignore this error and restore default error handling
OnErrorStop
// continue normal processing
GoTo NORMAL
[/code]
|
|
Wed Sep 17, 2008 2:41 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7949
|
|
|
|
You are overwriting the last error by executing a successful operation (Dim is an executable statement)
To see what I mean, move Dim line to the beginning of the script and run your code again. In your case, GetLastError should be the first statement in the error handler.
Alternatively,
 |
 |
OnErrorContinue
// attempt to delete the file
FileDelete( "c:\\data\\accounts.old" )
GetLastError message
NotEqual message, "", we_got_an_error |
|
|
Wed Sep 17, 2008 3:10 pm |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|