Added some error-catching code

Feel free to revert if you see a HUGE problem, but I thought this was an OK solution to catch unexpected runtime errors