Added an error handler to print any errors to the console instead of causing application crashes.