0

私は、laravel 5.0で作成されたコマンドアプリのコードをtry .. catchでシステムコマンドを使用しています。例外がある場合、私のキャッチは機能しません。

use Illuminate\Support\Facades\Log;
...
try {
  system('.dump master | sqlite3 ' . $older . ' > ' . storage_path() . '/tmp/' . $tabla . '.sql' );
} catch ( \Exception $e) {
  Log::alert('Problem import old table '. $tabla . $e->GetMessage());
}

シェルにエラーが表示されますが、自分のlaravelログには書きません。(ログ:アラート)

4

2 に答える 2

0

php でスロー例外を使用します。 使用する参照リンクとサンプル例を次に示します。

<?php
/*
 * 
 * opcode number: 108
 */
try {
    $error = 'Always throw this error';
    throw new Exception($error);

    // Code following an exception is not executed.
    echo 'Never executed';

} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

// Continue execution
echo 'Hello World';
?>
于 2016-04-27T11:39:17.197 に答える