|
How do I do try/catch here? I cant find it on the wiki, but I find it hard to believe roblox lua doesnt have this...
|
|
|
pcall(f) - "f" is a function running in protected mode, it will then return a boolean telling you if your function had an error or not. This is equivalent to try/catch.
error(msg) - This is equivalent to throw, it lets you make your own error message. |
|
|
|
Actually, pcall returns a boolean showing whether it succeeded or not. And then, if it did, it will return the data returned by the function as second, third, etc arguments. If it didn't, it will return the error as a second argument. |
|
|
I'm not recommending this at all, but this is the closest I've managed to actual try/catch/finally syntax, without the loss of syntax highlighting (if I didn't care about highlighting I'd just go use loadstring and use [[]] quotes to completely eliminate the requirement of functions):
function try(tryt)
return {catch = function(catcht)
xpcall(tryt[1], catcht[1])
return {finally = function(finallyt)
finallyt[1]()
end
}
end,
finally = function()
pcall(tryt[1])
return function(finallyt)
finallyt[1]()
end
end
}
end
try {
function() print(i.i) end
} .catch {
function(err) warn(err) end
} .finally {
function() print("try statement finished") end
} |
|
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
Disgusting |
|
|
|
he waz talking about his t-shirt |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
No I was talking about war's code.
And war if you really don't know why your script is disgusting then I suggest relearning Lua. |
|
|
What does try and catch do |
|
Hedr0nJoin Date: 2016-01-05 Post Count: 1524 |
I don't even think cnt knows what he is talking about |
|
|
Cnt knows what he is talking about. |
|
Hedr0nJoin Date: 2016-01-05 Post Count: 1524 |
Yes I know I posted that for a reason |
|
|
@cnt You ought to learn that people code for different reasons. You like low-level things and you code for.. Well Idek, but I prefer to code for fun. Yes I make practical stuff. Yes I made useful stuff. But mostly, I do things for fun and for the sake of curiosity. If you can't appreciate that, then you need to learn to be a bit more open-minded and learn to respect other's opinions and hobbies, even if you don't necessarily agree with them. |
|
|
ew functions defined inside functions
you underestimate the power of the dank side |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
"learn to respect other's opinions and hobbies"
My hobby is making fun of your crap, so why don't you respect my hobby? Or are you special and unique and too sensitive to realize that I said your code sucks, not that it was useless (albeit it's useless because xpcall is sufficient). |
|
|
try {
function() print(i.i) end
} .catch {
function(err) warn(err) end
} .finally {
function() print("try statement finished") end
}
I like this style better, as there is no need for tables being passed.
try (
function() print(i.i) end
) .catch (
function(err) warn(err) end
) .finally (
function() print("try statement finished") end
) |
|
|
cnt i would like to see u do better
meow |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
xpcall
There, I did better with 10x less overhead and 10x more efficiency. |
|
|
First of all, in all honesty, I don't think that's a very healthy hobby. Secondly, this is still rather childish. Most of the stuff that gets posted here is terrible, yet for some reason, you're still here. You need to accept the fact we're not all like you. Just because I code something that sucks, as you call it, doesn't mean you have to publicly call it out it just for kicks. It's a rather immature thing to do. |
|
|
cnt, War can script circles around you. Go find another habit, picking on someone superior than you is childish and just makes you look weak.
~Terror |
|
|
'cnt i would like to see u do better '
I KNOW he could do better. I'm not claiming my code is GOOD. The only problem I have is him, after time and time again, insulting my code. He does this continuously, despite the fact it's not meant for his approval. It's childish, and immature. My code doesn't have to be up to YOUR standards cnt. |
|
|
"cnt, War can script circles around you."
No. |
|
DrHaximusJoin Date: 2011-11-22 Post Count: 8410 |
"cnt, War can script circles around you. Go find another habit, picking on someone superior than you is childish and just makes you look weak."
nice 34 posts, newfriend.
don't assert your opinion on topics you don't know anything about :^) |
|