dongyinzhi4689 2016-05-23 15:22
浏览 48
已采纳

Laravel 5.2 - 处理命令中调用的命令的异常

So I have a command(1) that is calling another command(1) (command 1 and 2 from here on in). However, if command 2 throws an exception it can't be caught by command 1 for some reason.

Does anyone know how to deal with exceptions on "command-ception"?

Here is my code:

public function handle()
{
    $this->client = $this->argument('client');

    try {
        // Create database
        $this->createClientDatabase();

        $this->call('migrate', [
            '--database' => $this->client,
            '--path' => 'database/migrations/aca',
        ]);

        // Import the information into the tables

    } catch (Exception $e) {
        $this->dropClientDatabase();
    }
}

To clarify, I create a database and connection on the fly but if something fails on the migration call I end up with an empty database and no way to catch the error. If something happens within $this->call() it simply dies and doesn't continue processing command 1.

  • 写回答

1条回答 默认 最新

  • duanhe4267 2016-06-09 14:41
    关注

    So the issue was default namespacing. You need to put a backslash before Exception like so \Exception when using namespaces or at least put a use statement (use Exception;).

    Because I did not do either of these it was looking for an Exception class within my current namespace and therefore wasn't catching anything.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题