Catch exceptions explicitly.

@lepture Please review it. Thanks.