catch

PHP catch kalit so‘zi

❮ PHP kalit so‘zlar ma’lumotnomasi

Misol

Istisnoni ushlang:

<?php try {   throw new Exception("This is an exception"); } catch(Exception $e) {   echo $e->getMessage(); } ?>
O‘zingiz sinab ko‘ring »

ULASHISH

Ta’rif va qo‘llanilishi

catch kalit so‘zi undan oldingi try blokidagi kod tomonidan chiqarilgan istisnolarni qayta ishlash uchun ishlatiladi.


Tegishli sahifalar

throw kalit so‘zi.

try kalit so‘zi.

finally kalit so‘zi.

try..catch.finally (istisnolar) haqida PHP istisnolar darsligimizda batafsil o‘qing.


Ko‘proq misollar

Misol

Bir nechta istisno turi uchun catch kalit so‘zidan foydalaning:

<?php try {   $rand = rand(0, 2);   switch($rand) {     case 0: throw new Exception();     case 1: throw new OutOfBoundsException();     case 2: throw new LogicException(); } } catch(OutOfBoundsException $e) {   echo "Caught an out of bounds exception"; } catch(LogicException $e) {   echo "Caught a logic exception"; } catch(Exception $e) {   echo "Caught an ordinary exception"; } ?>
O‘zingiz sinab ko‘ring »

❮ PHP kalit so‘zlar ma’lumotnomasi

W3Schools Pathfinder

Yutuqlaringizni kuzating – bu bepul!