public static void WhenException(Action executeWhenExceptionHasOccured) { // be robust and prevent masking the original error if (executeWhenExceptionHasOccured == null) { return; } if (InException) { executeWhenExceptionHasOccured(); } } }