error handling in yii web service

Greetings,

I’m a beginner in php and Yii. I have created a web service and a method called authenticate. All of the code is surrounded with try catch but when specific type of error is triggered the service responce is a http response with the stack trace in the body:




HTTP/1.1 200 OK

X-Powered-By: PHP/5.2.6

Server: Apache/2.0.59 (Unix) PHP/5.2.6 DAV/2

Content-Type: text/xml;charset=UTF-8

Date: Thu, 09 Sep 2010 11:40:16 GMT

Content-Length: 1638

Connection: close




<h1>CException</h1>

<p>Undefined variable: _SESSION

.... stack trace is here



the function looks something like this:




    	try 

        {

    	      logic;

              return true;

        } 

        catch (Exception $e) 

        {

        	Yii::log($e, 'error', 'ConnectionsWS');

        }

        return false;



So my question is, why isn’t this error caught? If I throw an Exception myself inside the logic part it is caught. I don’t want the stack trace to be spit out if some unexpected error occurs. Is there a way to set errors to be handled globally in the yii app which works for web services as well? In C# I’m not used to a catch block not catching an exception :)

I have the same problem :confused:

any suggestions ??

what i do in this case is:

in the web-controller:




private function test() {

 $this->call_method_that_produces_runtime_error();

}


public function actions() {

 $this->test();

 return array( ...)

}



and then call the soap-server-url via browser. simple but effective ;)

It would appear there is an issue some where in your logic. I would try writing some unit tests for it to cover scenarios. See here for details.