Quote (Qord @ Apr 14 2014 10:20pm)
I haven't used a trap in anything I've written so far. Most of it's pretty small though, so it might not be necessary for those. I'm not even a fan of try/catch, but my boss says to use it so I am. I'm still newb enough to not worry too much about error handling, but I'm seeing the value of it as my tools get larger and more complex.
They both have their places.
For statements which may go wrong in localized areas of your script, you will want to wrap them in try/catch and do your error handling as needed. However, bigger scripts may have specific errors which can occur througout different parts of the scripts. Instead of having multiple try/catchs doing the exact same thing, you can define a trap, which for ALL exceptions that are trapped, no matter where in the script it occurs, will be piped through that one trap block.