updating exception handling to avoid deprecation warning