Edited by LoganDark, 18 June 2016 - 01:00 AM.
[Solved] Catch error, display custom error message
Started by LoganDark, Jun 18 2016 12:50 AM
4 replies to this topic
#1
Posted 18 June 2016 - 12:50 AM
I want to use shell.run to run a program that may not exist, and I have my own error message that I want to display instead of "No such program". Is that possible?
#2
Posted 18 June 2016 - 12:55 AM
Error handling and Exceptions over at the Lua manual will point you in the direction of pcall.
It would go a little like this
It would go a little like this
local ok, err = pcall(function() shell.run("program") end)
if not ok then
print("No program")
end
Edited by theoriginalbit, 18 June 2016 - 12:55 AM.
#3
Posted 18 June 2016 - 12:56 AM
theoriginalbit, on 18 June 2016 - 12:55 AM, said:
Error handling and Exceptions over at the Lua manual will point you in the direction of pcall.
It would go a little like this
It would go a little like this
local ok, err = pcall(function() shell.run("program") end)
if not ok then
print("No program")
end
Okay, thanks. I forgot about pcall.
#4
Posted 18 June 2016 - 01:16 AM
shell.run() doesn't actually error if the targeted file doesn't exist. You'd be better off using fs.exists() to check before attempting to run in the first place.
#5
Posted 18 June 2016 - 01:18 AM
Bomb Bloke, on 18 June 2016 - 01:16 AM, said:
shell.run() doesn't actually error if the targeted file doesn't exist. You'd be better off using fs.exists() to check before attempting to run in the first place.
Oh, okay.
Edit: So fs.combine shell.dir() and what to run?
Edit 2: I guess that's a yes
Edited by LoganDark, 18 June 2016 - 01:25 AM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











