Fixed a crash bug and implement error handling

* fixed a bug that incorrect arguments cause crash.
* add a new 'error' property to handle error when calling method