[Vtigercrm-developers] Day 4: Error handling

socialboostdk socialboostdk at gmail.com
Mon Dec 5 17:57:52 GMT 2016


Hi there,

Its a nice idea for you to send it out, but it is also sending a lot of
info for a full list, where no-one of us asked for it. So could you not
instead send 1 mail with the relevant links & suggestions, etc. instead of
forcing a daily mail?

Thanks :)

Best,
Chris.

On 5 December 2016 at 18:07, Holbok István <holbok at gmail.com> wrote:

> Today, in day 4 of our 5-day mini-course, we're going to discuss *Error
> handling*.
> Error handling
>
> For a long while, error handling was just about magical status codes for
> us. You know what I am talking about, right?
>
> When user submits an order, return 0 when the date is expired, return 1
> when there is no more stock, return 2 when user is not eligible for current
> order, return 3 when user is not logged in, and return 4 when order is
> placed successfully.
>
> Have you done anything similar above? If so, you need to learn a better
> way of error handling. We did, and we’ve never looked back.
>
> Error codes are terrible; they are meaningless to new developers; are hard
> to keep track of because they contain no real information.
>
> Error handling should be done properly with exceptions.
>
> A lot of errors in our applications are exceptions. They are exceptional
> cases in our applications, which we should handle directly as soon as they
> occur.
>
> PHP introduced Exception class in PHP 5.
>
> Similar to exceptions in other languages, an exception is "thrown" when an
> error occurs:
>
> throw new Exception('No more stock')
>
> And an Exception class ought to be handled in a catch clause:
>
> catch (Exception $e) {
>      echo 'Caught exception: ',  $e->getMessage(), "\n";
> }
>
> To make sure some code always runs such as closing a database connection,
> we use a finally clause:
>
> finally {
>      // close PDO connection
> }
>
> Now you know error handling does not mean returning magical codes. Using
> exceptions to handle exceptional cases is the way to go!
>
> Tomorrow, in the final installment of this course, we'll take a look at *Test
> Driven Development.*
>
> You won't want to miss it,
>
> Keep learning!
> Xu
> www.startutorial.com
>
>
> Kindest regards:
> Istvan Holbok
>
> _______________________________________________
> http://www.vtiger.com/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20161205/f715c335/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: open
Type: image/gif
Size: 43 bytes
Desc: not available
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20161205/f715c335/attachment.gif>


More information about the vtigercrm-developers mailing list