Understanding Exceptions in PHP
DRANK
<= 0) { throw new LogicException('Quantity must be greater than 0'); } if (!productExists($productId)) { throw new NotFoundException($productId); } $stock = getStock($productId); if ($stock < $quantity) { throw new InsufficientStockException($productId, $quantity, $stock); } // DBへの保存に発生する例外はcatchしない return Order::create(['productId' => $productId, 'quantity' => $quantity]); } 11/63