Page 1 of 1

exception object undefined get properties?

PostPosted: October 25th, 2013, 4:12 pm
by carlosqt
Hi there,

I think there is a bug in Phalanger when throwing and catching Phalanger and System exceptions.

In a /pure phalanger console program, if I throw a new System\Exception I get an Error message and the the program continue execution without going to the catch part. However, if I throw a ErrorException or OutOfRangeException exceptions with the message, severity, etc. they both go into the catch, but the exception variable gives an undefined property Notice message when accessing those 2 properties even though the object, in this case $e, has them.


Here is the code and further down the output with the error and notice messages:
Example:

Code: Select all
<?php
use System\Exception;
class Program
{
   static function Main()
   {
        try 
        { 
            throw new System\Exception("System.Exception");
           
            $arr = NULL;
           
            if (is_null($arr))
            {
                throw new ErrorException(
                "Object reference not set to an instance of an object.",
                0, E_ERROR);
                /*throw new S\NullReferenceException(
                "Object reference not set to an instance of an object.");                   
                throw new S\Exception(
                "Object reference not set to an instance of an object.");*/
            }
            if (isset($arr[100][100]))
            {
                throw new OutOfRangeException(
                "Index was outside the bounds of the array.", 0);
                /*throw new \ErrorException(
                "Index was outside the bounds of the array.", 0, \E_ERROR);                   
                throw new S\IndexOutOfRangeException(
                "Object reference not set to an instance of an object.");
                throw new S\Exception(
                "Object reference not set to an instance of an object.");*/
            }
        } 
        catch (OutOfRangeException $e) 
        { 
            echo "\nException: ", "OutOfRangeException", $e->getMessage, "\n"; 
        }
        catch (ErrorException $e) 
        { 
            echo "\nException: ", "ErrorException", $e->getSeverity, $e->getMessage, "\n";               
        }             
        catch (System\Exception $e)
        {
            echo "\nException: ", "Exception", $e->getMessage, "\n"; 
        }
       
      fgets(STDIN);
      return 0;
   }
}

?>


exceptions.png



The output:

Re: exception object undefined get properties?

PostPosted: October 26th, 2013, 2:49 pm
by Jakub Misek
Thank your for reporting the issue.

- Throwing System\Exception has been fixed.

- Add accessing PHP Exception message and severity; getSeverity() and getMessage() are methods (not properties) so there is missing "()" in your sample. To access System\Exception message, use ->Message property.

Regards,

Re: exception object undefined get properties?

PostPosted: October 30th, 2013, 8:12 am
by carlosqt
Great its now fixed. Will look at it when a new release is available.

Regarding the method call instead of a property shame on me lol, definitely I was a bit out of focus. I added the parenthesis () to both calls and they worked as expected.

Thanks for your quick response.
Best Regards,

Carlos

Re: exception object undefined get properties?

PostPosted: October 30th, 2013, 5:55 pm
by Jakub Misek
Great it works :-) Thank you for giving us know!