14 posts
Posted 11 March 2012 - 10:39 PM
Hi, I'm trying to add error support for a file manager I'm making, but for some reason pcall() isn't catching an error if the file I'm trying to delete is restricted.
if pcall(fs.delete(fileOptionsFile)) then misc.popup("Successfully deleted file.", 2)
else misc.popup("Failed to delete file.", 2)
end
1604 posts
Posted 11 March 2012 - 10:46 PM
You are calling the function fs.delete() and passing it's return value to pcall.
When using pcall, you should pass the parameters like this:
pcall(function, param1, param2, ...)
14 posts
Posted 11 March 2012 - 11:04 PM
Alright, but when I try:
if pcall(fs.delete(), fileOptionsFile) then misc.popup("Successfully deleted file.", 2)
else misc.popup("Failed to delete file.", 2)
end
It says "string expected, got nil" ? I made sure that fileOptionsFile is a string and that the error isn't in misc.popup()
1604 posts
Posted 11 March 2012 - 11:06 PM
Just pass the function, don't call it, remove the ()
It should be like this:
if pcall(fs.delete, fileOptionsFile) then
misc.popup("Successfully deleted file.", 2)
else
misc.popup("Failed to delete file.", 2)
end
14 posts
Posted 11 March 2012 - 11:07 PM
Alright, thanks! :mellow:/>/>