SitePoint Sponsor

User Tag List

Page 3 of 3 FirstFirst 123
Results 51 to 55 of 55
  1. #51
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    The Netherlands
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jayboots View Post
    Hmm. Well, it is not at all clear to me why you would want to do the former. Maybe your intention is to simply log some condition's outcome?
    Throw an Exception instance, just have internals take care of instantiation.
    Quote Originally Posted by jayboots View Post
    Besides, I don't see how much more convenient it really is
    Same reason shorthand notation exists in for example JavaScript, Python and CSS: brevity. I guess it's a matter of taste.
    Last edited by michel; Jan 11, 2007 at 07:09.

  2. #52
    Resident Code Monkey Chris Corbyn's Avatar
    Join Date
    Nov 2005
    Location
    Melbourne, Australia
    Posts
    713
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 33degrees View Post
    There's a reason for this though. Yes, javascript lets you throw any type of object as an exception, but that's mainly because there aren't any classes or interfaces, so there'd be no other way to do it anyway. The downside of this is that, unlike php, you can only have a single catch statement; you can't have multiple catch statements for different types of errors, which means you have to add if statements and instanceof operators, which is messy.
    Sorry, just had to point something out here, albeit, something IE kindly haven't implemented:

    Quote Originally Posted by Mozilla Dev
    Multiple catch Blocks
    A single try statement can contain multiple conditional catch blocks, each of which handles a specific type of exception. In this case, the appropriate conditional catch block is entered only when the exception specified for that block is thrown. You can also include an optional catch-all catch block for all unspecified exceptions as the final catch block in the statement.

    For example, the following function invokes three other functions (declared elsewhere), which validate its arguments. If a validation function determines that the component that it is checking is invalid, it returns 0, causing the caller to throw a particular exception.

    Code:
    function getCustInfo(name, id, email)
    {
       var n, i, e;
    
       if (!validate_name(name))
           throw "InvalidNameException"
       else
           n = name;
           if (!validate_id(id))
              throw "InvalidIdException"
           else
              i = id;
           if (!validate_email(email))
              throw "InvalidEmailException"
           else
              e = email;
           cust = (n + " " + i + " " + e);
           return (cust);
    }
    The conditional catch blocks route control to the appropriate exception handler.
    Code:
    try {
    // function could throw three exceptions
       getCustInfo("Lee", 1234, "lee@netscape.com")
    }
    
    catch (e if e == "InvalidNameException") {
    // call handler for invalid names
       bad_name_handler(e)
    }
    
    catch (e if e == "InvalidIdException") {
    // call handler for invalid ids
       bad_id_handler(e)
    }
    
    catch (e if e == "InvalidEmailException") {
    // call handler for invalid email addresses
       bad_email_handler(e)
    }
    
    catch (e){
    // don't know what to do, but log it
       logError(e)
    }

  3. #53
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unicode support!

    Everything else can wait for PHP7 imho.

  4. #54
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Slovakia
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am starting using PHP 5.3 in real project. I have found some missing features in PHP 5.3
    - full Unicode support in core
    - namespace visibility
    bugs.php.net/bug.php?id=45681

  5. #55
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You do realise that this thread is 3 years old, right?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •