Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Better way of error handling?

What are best way of error handling? This is what I came up with:

class test {

    public static function Payment($orderid, $total) {
        if (empty($orderid) && empty($total)) {
            return array('status' => 'fail', 'error' => 'Missing Data');
        }
    }

}

I heard about Try/Exceptions but how to fit that into my code? If you could provide example that would be great!

like image 361
user622378 Avatar asked Dec 27 '22 20:12

user622378


1 Answers

If you use PHP 5, you can handle error with exception :

http://fr2.php.net/manual/en/class.exception.php

This way is cleaner than manual set exception message, because you have access to a try catch system and you can isolate exception handling

like image 115
Charles Avatar answered Dec 30 '22 09:12

Charles