fix matlab crash bug on error