Exception handling is how you manage control flow within a WinCron script.
This is convenient because you can handle an error without an explicit -if directive.

In the C programming language, you might use an IF statement to handle an error as follows:
Quote:
Code:
Some_function()
{
    if (something_bad)
        Error_function();
    else
    {
        // do normal stuff 
    }
}


But WinCron scripts are flat, there is no ugly nesting to muddy-up the logic.
You simply register an exception handler script to run in the case of an error, or other exceptional condition (like no more files, rename failed, can’t delete file, etc..)

The following script is really short, but I have made heavy use of comments, so you should be able to simply read the script.

##
# Read files from a directory and move them to another directory
{
# start now and schedule subsequent file moves every 10 seconds
-start -inc 0 0 0 10

# set up an error handler for file operations that fail
-action -onerror file_operation_failed

# set an environment variable with the name of the function we are about to call
# This is used in case of a failure so we can print the name of the function
-action -set OP=getFile

# Read each .BMP file from c:\temp and store the name in FILE_NAME
# if there are no files matching *.bmp, this action will throw an exception
-action -getFile -oldest c:\temp\*.bmp FILE_NAME

# set an environment variable with the name of the function we are about to call
-action -set OP=move

# move the file to a temp location
# name the file with the current minute (%M%) and second (%S%)
# name will endup looking like "c:\save\10-58.bmp"
# throws an exception on error
-action -move %FILE_NAME% c:\save\%M%-%S%.bmp
}

##
# file operation failed
# Simply print the operation that failed (stored in environment var %OP%)
# and *break* out of the calling script
# The script will execute next time it is scheduled (in 10 seconds)
{
-name file_operation_failed
-action -print file operation %OP% failed
-action -print will try later
-action -return break
}

So the script wakes-up every 10 seconds and looks to see if there are any .BMP files in c:\temp.
If none are found, an exception is raised and control is transferred to the file_operation_failed script.
When the file_operation_failed script runs, it simply prints a message, then breaks out of the calling script, effectively skipping to the end of the script. The Job will be rescheduled as normal.
In the case where a .BMP file is found, the script continues to the next lines where the file is moved to another directory. Again, if there is a failure during the file move, an exception is raised.
_________________________
Regards,
Luke Tomasello