exception handling in listener to prevent crashes