adding code to catch errors and display warnings properly