generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

try/catch in roblox lua?

Previous Thread :: Next Thread 
Waccsadac is not online. Waccsadac
Joined: 02 Jun 2012
Total Posts: 2440
16 Jan 2016 12:03 PM
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...
Report Abuse
wonderful72pike is not online. wonderful72pike
Joined: 13 Jul 2010
Total Posts: 7009
16 Jan 2016 12:05 PM
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.
Report Abuse
Waccsadac is not online. Waccsadac
Joined: 02 Jun 2012
Total Posts: 2440
16 Jan 2016 12:20 PM
Thanks
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
16 Jan 2016 12:31 PM
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.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
16 Jan 2016 12:38 PM
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
}
Report Abuse
LongKillKreations is not online. LongKillKreations
Joined: 14 Feb 2014
Total Posts: 4502
16 Jan 2016 12:39 PM
nice warspy
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
16 Jan 2016 02:59 PM
Disgusting
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
16 Jan 2016 03:29 PM
And why is that, cnt?
Report Abuse
Waccsadac is not online. Waccsadac
Joined: 02 Jun 2012
Total Posts: 2440
16 Jan 2016 11:17 PM
he waz talking about his t-shirt
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
16 Jan 2016 11:40 PM
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.
Report Abuse
bosswalrus is not online. bosswalrus
Joined: 04 Jan 2013
Total Posts: 5430
16 Jan 2016 11:57 PM
What does try and catch do
Report Abuse
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
16 Jan 2016 11:59 PM
I don't even think cnt knows what he is talking about
Report Abuse
bosswalrus is not online. bosswalrus
Joined: 04 Jan 2013
Total Posts: 5430
17 Jan 2016 12:00 AM
Cnt knows what he is talking about.
Report Abuse
checkplate is not online. checkplate
Joined: 05 Jan 2016
Total Posts: 1379
17 Jan 2016 12:02 AM
Yes I know I posted that for a reason
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
17 Jan 2016 07:17 PM
@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.
Report Abuse
cpmoderator12345 is not online. cpmoderator12345
Joined: 26 Jan 2013
Total Posts: 15651
17 Jan 2016 07:21 PM
ew functions defined inside functions



you underestimate the power of the dank side
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
17 Jan 2016 07:23 PM
"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).
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
17 Jan 2016 07:46 PM
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
)
Report Abuse
matt089720 is not online. matt089720
Joined: 06 Dec 2012
Total Posts: 7
17 Jan 2016 07:46 PM
cnt i would like to see u do better


meow
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
17 Jan 2016 07:51 PM
xpcall

There, I did better with 10x less overhead and 10x more efficiency.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
17 Jan 2016 07:52 PM
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.
Report Abuse
ScriptingIntoTerror is not online. ScriptingIntoTerror
Joined: 17 Oct 2012
Total Posts: 64
17 Jan 2016 07:55 PM
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
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
17 Jan 2016 07:55 PM
'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.
Report Abuse
bosswalrus is not online. bosswalrus
Joined: 04 Jan 2013
Total Posts: 5430
17 Jan 2016 07:56 PM
"cnt, War can script circles around you."

No.
Report Abuse
DrHaximus is not online. DrHaximus
Joined: 22 Nov 2011
Total Posts: 8410
17 Jan 2016 07:56 PM
"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 :^)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 3Go to page: [1], 2, 3 Next
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image