引发错误时如何重新启动节点模块功能

时间:2018-10-03 15:32:16

标签: node.js error-handling try-catch

我正在尝试从外围设备读取详细信息,但是即使将其包装在try / catch块中也会偶尔引发错误,这会停止运行时执行。

 private void eventHandler() {
        button2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {

            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:0377778888"));

            if (ActivityCompat.checkSelfPermission(MainActivity.this,
                    Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                return;
            }
            startActivity(callIntent);
        }
    });
}
  

/home/pi/Documents/node_modules/i2c-bus/i2c-bus.js:355   返回i2c.readI2cBlockSync(peripheralSync(this,addr),cmd,length,buffer);
  错误:,发送时发生通讯错误

我想一直重启直到满足条件。

当引发错误时,如何捕获此错误并重新启动const ina219 = require('ina219') const DELAY_MS = 15 try { let getVoltage = ina219.calibrate32V1A(() => { let int = setInterval(() => { ina219.getShuntVoltage_mV((volts) => { console.log(volts) }) }, DELAY_MS) }) } catch (error) { console.log(error) if(conditionIsMet) { // exit try-catch } else { getVoltage // restart getVoltage } }

0 个答案:

没有答案