Added Error catching functionality

Added Error catching functionality and logging capability