Saturday 15 May 2010

php - Why is my exception thrown from a closure not caught? -


I have written a PHPUnit test which checks that an exception is thrown at the close when applied with a method . The closure function is passed as a logic in that method, with an exception being entered from it.

  public function testExceptionThrownFromClosure () {$ the-> $ -externalResourceTemplate- & gt; This- & gt; Unexpected URL, $ this- & gt; _Palam one, function ($ anything) {new something _exception ('message');}); $ This- & gt; Failed ("expected exception not found"); } Hold (some_expression $ E) {var_dump ($ e-> getMessage ()); Die; }}   

code for the specified function on ExternalResourceTemplate

  get public function ($ url, $ params, $ off) {try {$ this- & Gt; _getHttpClient () - & gt; SetUri ($ url); Forex currency ($ parameter as $ key $ $ parameter = & gt; $ value) {$ this- & gt; _getHttpClient () - & gt; Set ParameterGet ($ key, $ value); } $ Response = $ this- & gt; _getHttpClient () - & gt; request (); $ Refund ($ response-> getBody ()); } Hold (exception $ e) {// log // monitor}}   

Any idea why the unsuccessful effect statement is called? Can not you catch exceptions to PHP or have a specific way of dealing with them, which I do not know.

Exceptions to me should only promote the return stack, but it does not appear to be a bug? FYI is running PHP 5.3.3

Thank you for answering ... < P> Managed to understand the problem. It seems that the problem is that the attempted block is being implemented where the request to close is requested. Which is understandable ...

then the above code should be available

  public function ($ url, $ params, $ off) {try {$ this- & Gt; _getHttpClient () - & gt; SetUri ($ url); Forex currency ($ parameter as $ key $ $ parameter = & gt; $ value) {$ this- & gt; _getHttpClient () - & gt; Set ParameterGet ($ key, $ value); } $ Response = $ this- & gt; _getHttpClient () - & gt; request (); $ Refund ($ response-> getBody ()); } Hold (exception $ e) {// log // monitor some cispxx option ("exception is actually caught"); }}   

So it seems that in PHP 5.3.3 there was not a bug after all that was mentioned. My mistake.

No comments:

Post a Comment