Assuming that the UDF returns error codes, you need to check immediately after the function call, i.e.:
Code:
$DirList2 = DirList($path,4+2+1)
If @ERROR
; Error reporting here.
Else
FOR EACH $x in $DirList2
...
Next
EndIf



There is one error that you might get back which is a "no more items" style error - this is not an error condition, it just means that the directory enumeration reached the end of the list so you should ignore it.