This can throw, you should wrap it in a try...catch.  Also note, this function returns nothing.  You might consider returning true or false depending on whether things pass/fail through this function.  It would be good to standardize the exits.