Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92428 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67513 invoked from network); 18 Apr 2016 19:36:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Apr 2016 19:36:44 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.169 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.192.169 mail-pf0-f169.google.com Received: from [209.85.192.169] ([209.85.192.169:33795] helo=mail-pf0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0E/1E-11975-B4735175 for ; Mon, 18 Apr 2016 15:36:43 -0400 Received: by mail-pf0-f169.google.com with SMTP id c20so83793622pfc.1 for ; Mon, 18 Apr 2016 12:36:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=co6KvNoQ3r4QrIfte4L2UlWxr+tQttaj+jY7p4j2DRY=; b=RJWWlkFj5+72DCg8RVohCyzwZt509QzC07sytKcifFLcCRt7lq89MneBwBNRJYVHP6 vZrN7agf2QJqy6ceTFgvDDeps35IGf0444CP49+1CVm5bt9QO3t9LQhF5wEuodxjlhnV 5BJpetI58qG23GJDHhGbWLP+1S071NOGjpD30SjLfTE2YkQNPoTZaGNgenn2uzf/myMv BmKcQ/1GU72qHYzz996K01PG5wBI4m/7YP6X+/Xa2xpdLeNrV8qIzawbGzWNMgdHwc/b JQIxX2yPmYiozWOCr3loCk5EgDsFd8/r5LgcIemCo/UDB41ovb6Bnarg0sCG3jYYbNRu 1WOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=co6KvNoQ3r4QrIfte4L2UlWxr+tQttaj+jY7p4j2DRY=; b=PKfvzXVEbcz4KrE9eKj/NTETf9YM/XzB70EpTnpB88ClskCs7zG2VGY98C6SQKtDba FOqQKK0JyZ5+ueTLIby0gAYT5ZmhKU57Bsb1XNd/sS6OxHOywiPGwesMX1z/uCn4Y/fM cZP4UC0QW0NwEzlwaPL5cqRaz99w5X0HhaF3Uan83gc5HFn2CRuXgUsNmVIUxSdLbVR9 3yPAySaGDsyvVAMUpDMaySsb+KNudhUk5SppNHHAsVyK8wdXSOYyZ0GMAe0B4fe6Xc+B myfpYNqbJ2N0qC+Vz/p7QDhpRtUMf/3mC3w8de9PcZWso8mK67iNRuGN6BQj5pL6NKOO DCjg== X-Gm-Message-State: AOPr4FX8iUBHOHe7mmOeb6GC262uoY6OBjeDvqbMAALxaLxvwEQQh4mtKpBybjGxT8+XIg== X-Received: by 10.98.1.69 with SMTP id 66mr53040515pfb.10.1461008200034; Mon, 18 Apr 2016 12:36:40 -0700 (PDT) Received: from Stas-Air.local (76-220-46-95.lightspeed.sntcca.sbcglobal.net. [76.220.46.95]) by smtp.gmail.com with ESMTPSA id 6sm28467650pfx.68.2016.04.18.12.36.37 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 18 Apr 2016 12:36:38 -0700 (PDT) To: Derick Rethans , Marco Pivetta References: Cc: Dan Ackroyd , =?UTF-8?B?QnJvbmlzxYJhdyBCaWHFgmVr?= , PHP internals Message-ID: <57153744.3030802@gmail.com> Date: Mon, 18 Apr 2016 12:36:36 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [VOTE] Catching Multiple Exception Types From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > Even this is a scary way to do it. As you don't know which exception > class you have, how would you know how to handle each separately. You'd > have to if ($caught instanceof InvalidArgumentException) etc to be sure > that what you're doing with the object is allowed. I just recently had a case where I used something similar in Java code, so I can tell when it's useful: - You call some complex object that can fail for a lot of reasons (like HTTP client talking to remote service) - It can fail with a number of exceptions because something went bad - i.e. network is bad, DNS is bad, server is down, service is too busy, your request syntax is wrong, request is correct but you're not allowed to execute it, etc. - These causes can be roughly separated into two groups - requests that we can and should repeat - e.g. "server too busy" situation, and those that we should not repeat, e.g. "bad syntax" situation - Furthermore, failures can be "soft" - fail this request but continue next ones in the batch, or "hard" - drop everything and call for help because something is seriously broken. In this situation, grouping exceptions - which, due to being from different layers of the complex object do not follow any single structure - becomes very convenient. Of course it is possible to write a long tree of copy-paste handlers for each of the three cases, but it's annoying. Much cleaner to have just three branches. And of course I don't want to do something like catch(Exception) because *shudder*... > say, it's very likely they should be handled differenty anyway. Or > rather, very generically, which you can do with "catch (Exception $e)". catch(Exception) is practically never a good idea, unless you really are able to handle *every* exception. Now in PHP that includes parse errors, type errors, etc. I don't think any random code - except for a very generic final error handler - would ever want to do that. -- Stas Malyshev smalyshev@gmail.com