Menu

错误处理


id: guide-errors
title: Error Handling

All functions in Node-Serialport follow two conventions:

  • Argument errors throw a TypeError object. You'll see these when functions are called with invalid arguments.
  • Runtime errors provide Error objects to the function's callback or emit an error event if no callback is provided. You'll see these when a runtime error occurs, like trying to open a bad port or setting an unsupported baud rate.
  • Promise based functions reject a TypeError for an argument error, or a standard Error for runtime errors.

You should never have to wrap a Node-Serialport object in a try/catch statement if you call the functions with the correct arguments.

上一篇 下一篇
讨论数量: 0

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
刻意练习,每日精进。
~
点赞
200
浏览
0
讨论