Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Try-Catch Blocks Keep Destroying My Script

I am currently developing a very complicated script (which is complicated even more by the fact that I do not understand how to properly use the JSON.parse() method) for the Legend of the Five Rings Roleplaying Game (4th edition), and am attempting to idiot-proof it for those that will be actually using it. However, every time I attempt to add a simple try-catch block, the script seems to blow up in my face. If you need a link to the script (sorry, no Gist yet -- I don't know how to make them and I have this under RCS locally), I can provide a link to where I have it publically viewable on Google Drive (the link's needed though). I just need to know how to properly implement try-catch blocks into a Roll20 API script.
I honestly haven't tried it in a script, but in theory this is what they look like: try { //Do stuff here that might cause an error. } catch (e) { //"e" is the error } So you're saying if you have a normal functioning script and just add that to the end of it, nothing works?
Now that I think of it, I might have been leaving out the "(e)" part of the catch statement. It's been around a month since I've last worked on it. I'll try adding one again and report back soon. Thanks for reminding me how Javascript does these things (I honestly thought I remembered, but I guess I didn't). Thanks for the quick response Riley!
I implemented a try-catch block and it itself is not destroying the script, so I must have been missing something the first time. However, I tell my catch block to run a call to sendChat() if the failure happens, and I think I am giving cases that would trigger that sendChat() but never see it come up. I'll do some more testing on that front, but thanks for helping me at least figure out where I was going wrong with the try-catch bllock syntax itself.