NYCPHP Meetup

NYPHP.org

[nycphp-talk] If/else vs Try/catch

Ben Sgro (ProjectSkyLine) ben at projectskyline.com
Wed Nov 28 11:25:12 EST 2007


Hello Scott,

Thanks. I'll read up on it now...and post my thoughts.

Before I read I'll ask this question. What's the difference between
this example below and what you just explained?

bens at arc90-dev-02:~/webdev$ php test.php
Gotcha!
bens at arc90-dev-02:~/webdev$ cat test.php
<?php

function a($val)
{
        if ( $val < 0 ) return FALSE;
        if ( $val >= 0 ) return TRUE;
}

if ( a(-1) )
{
        printf("Not here\n");
}
else
{
        printf("Gotcha!\n");
}


- Ben
----- Original Message ----- 
From: "Scott Mattocks" <scott at crisscott.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Wednesday, November 28, 2007 11:11 AM
Subject: Re: [nycphp-talk] If/else vs Try/catch


> Ben Sgro (ProjectSkyLine) wrote:
>> I see ample use of try/catch. Why? Why is it better/different than 
>> if/else?
>
> You are talking about two completely different things here. If/else is for 
> testing a condition. Try/catch is for handling exceptions. If an exception 
> is thrown within a try/catch block the code in the catch section will be 
> executed. The two are not interchangeable. You should read up on exception 
> handling if you think you may need to use try/catch.
>
> http://us2.php.net/manual/en/language.exceptions.php
>
> -- 
> Scott Mattocks
> Author: Pro PHP-GTK
> http://www.crisscott.com
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php 




More information about the talk mailing list