Perhaps not the UDF but maybe either the rest of the code or the UDF in that if you attempted to do a read and did not have permissions then it should have given an error that could have been tested for in the script and write to a log if required.