PHP သည် Keyword ကိုဖမ်း သည်။
ဥပမာ
ခြွင်းချက်တစ်ခုဖမ်းပါ-
<?php
try {
throw new Exception("This is an exception");
}
catch(Exception $e) {
echo $e->getMessage();
}
?>
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
သော့ချက်စကားလုံးကို ယခင် စမ်းသုံးပိတ်ဆို့ခြင်းcatch
တွင် ကုဒ်မှချထားသော ခြွင်းချက်များကို ကိုင်တွယ်ရန် အသုံးပြုသည် ။
ဆက်စပ်စာမျက်နှာများ
အဓိက throw
စကားလုံး။
အဓိက try
စကားလုံး။
အဓိက finally
စကားလုံး။
ကျွန်ုပ်တို့၏ PHP Exceptions Tutorial တွင် try..catch.finally (ခြွင်းချက်များ) အကြောင်း ပိုမိုဖတ်ရှုပါ ။
နောက်ထပ် ဥပမာများ
ဥပမာ
ခြွင်းချက်အမျိုးအစားများစွာအတွက် catch ကိုသုံးပါ
<?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";
}
?>
❮ PHP သော့ချက်စာလုံးများ