switch from try..catch to typeof is undefined