Fix PR17222 - catching derived classes from thrown null pointer. Adds tests, too