Add `undefined` check.

Add `undefined` check.

`handler` could be `undefined`.