0

致命错误:C:\xampp\htdocs\jsms\sms.php:61 中的未捕获异常“异常”和消息“无法设置 COM 端口,请检查它是否正确”堆栈跟踪:#0 C:\xampp\htdocs\jsms \sms.php(17): gsm_send_sms->init() #1 {main} 在第 61 行的 C:\xampp\htdocs\jsms\sms.php 中抛出 public function init() {

    $this->debugmsg("Setting up port: \"{$this->port} @ \"{$this->baud}\" baud");

    exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval);

    if ($retval != 0) 
    {
        throw new Exception('Unable to setup COM port, check it is correct');
    }

    $this->debugmsg(implode("\n", $output));
    $this->debugmsg("Opening port");

    //Open COM port
    $this->fp = fopen($this->port . ':', 'r+');

    //Check port opened
    if (!$this->fp) {
        throw new Exception("Unable to open port \"{$this->port}\"");
    }
4

1 回答 1

0

你没有捕捉到你抛出的异常:

if ($retval != 0) 
{
    throw new Exception('Unable to setup COM port, check it is correct');
}

如果抛出

exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval);

返回一个错误 int(任何东西!= 0)。

利用:

try {
    exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval);
    if ($retval != 0) 
    {
        throw new Exception('Unable to setup COM port, check it is correct');
    }
} catch (Exception $e) {
    // do whatever you want to handle the error
}
于 2013-02-16T19:57:45.293 回答