Thuta Learning
PHP
AdvancedProgrammingbeginner

Exceptions & Error Handling

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Exceptions & Error Handling ရဲ့PHP runtime နဲ့web behavior ကိုရှင်းပြနိုင်ရန်
  • Normal, boundary, invalid နဲ့failure cases စမ်းနိုင်ရန်
  • Secure, maintainable PHP code ရေးနိုင်ရန်

Recover သို့meaningful translate လုပ်နိုင်သောboundary မှာသာfailure ကိုcatch လုပ်ပါ။

ပိုပြီးနားလည်ထားရမယ့် အချက်

Throwable hierarchy, warnings/notices, exceptions နဲ့fatal failures ကိုlogging/user-response policy ဖြင့်ခွဲပါ။ Specific failures catch လုပ်၊cause/context ထိန်းပြီးglobal boundary မှာsafe response ပြန်ပါ။

လက်တွေ့မှာ ဘယ်လိုအသုံးချမလဲ

Exceptions & Error Handling example ကိုnormal, boundary, invalid နဲ့failure inputs ဖြင့်run/test လုပ်ပြီး output, warnings, exceptions နဲ့side effects ကိုမှတ်တမ်းတင်ပါ။

ဒီသင်ခန်းစာပြီးရင်

php
<?php
declare(strict_types=1);
function divide(float $a, float $b): float {
    if ($b == 0.0) throw new InvalidArgumentException('zero divisor');
    return $a / $b;
}
try { echo divide(10, 2); } catch (InvalidArgumentException $e) {
    error_log($e->getMessage()); echo 'Invalid calculation';
}
You should see
5

ကိုယ်တိုင်စမ်းကြည့်ရန်

Exceptions & Error Handling example ကိုnormal, boundary, invalid နဲ့failure inputs ဖြင့်run/test လုပ်ပြီး output, warnings, exceptions နဲ့side effects ကိုမှတ်တမ်းတင်ပါ။

Security/Common Mistake သတိပေးချက်

Production response ထဲstack trace သို့secrets ပြခြင်းကအရေးကြီးအချက်အလက်ပေါက်ကြားစေပါတယ်။

PHP Language ReferencePHP Documentation Group

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Production response ထဲstack trace သို့secrets ပြခြင်းကအရေးကြီးအချက်အလက်ပေါက်ကြားစေပါတယ်။
  • Sample output တစ်ခုမှန်ရုံဖြင့် input, output, authorization နဲ့failure paths အားလုံးမှန်ပြီဟုယူဆခြင်း။

လက်တွေ့လေ့ကျင့်ခန်း

Exceptions & Error Handling example ကိုnormal, boundary, invalid နဲ့failure inputs ဖြင့်run/test လုပ်ပြီး output, warnings, exceptions နဲ့side effects ကိုမှတ်တမ်းတင်ပါ။

You'll know it worked when: 5

Exceptions & Error Handling | Thuta Learning