Add timeout to wait and deal with exception.