首页 > 其他分享 >Laravel 异常错误信息处理

Laravel 异常错误信息处理

时间:2023-03-24 10:02:34浏览次数:40  
标签:Laravel 信息处理 错误 Exception new throw


手动抛出错误

try{
	
	$num1 = 3;
	if ($num1 == 3) {
		throw new \Exception("自定义错误");
	}
}catch(\Exception $exception){
	info($exception->getMessage());
}
日志打印出了: 自定义错误

Laravel 异常错误信息处理

use Illuminate\Http\Exceptions\HttpResponseException;

/**
 * Laravel 异常错误信息处理
 * @author wgchen
 * @date 2022-2-14
 */
public function checkCrmLegal()
{
    throw (new HttpResponseException(response()->json([
        'status_code' => 422,
        'message' => 'asdf',
    ], 200)));
}

Laravel 异常错误信息处理_Laravel

use Symfony\Component\HttpKernel\Exception\HttpException;

throw new HttpException(400, 'asdf');

Laravel 异常错误信息处理_php_02


标签:Laravel,信息处理,错误,Exception,new,throw
From: https://blog.51cto.com/u_13571520/6146819

相关文章