You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

catch blocks never execute in Custom Controller

Accepted answer
7
Views
5
Comments
edited Sep 13, 2016 6:17AM in UI Extensibility 5 comments

Content

I am trying to get some error handling into my custom controller and I have set up a test controller trying to figure out why my catch block code never executes. You can see the code below.

If I throw an exception outside of the try block it returns a 500 internal server error, throwing inside of the try block causes no errors but ceases execution, "I shouldn't be here" never gets echoed but then neither does "Catch". I am not sure what is going on here.

Version

Service Cloud Feb2015, Customer Portal 3.0.2

Code Snippet

             <?php
namespace Custom\Controllers;

require_once(get_cfg_var('doc_root') . '/include/ConnectPHP/Connect_init.phph' );
initConnectAPI();				
use RightNow\Connect\v1_2 as RNCPHP;

class ErrorTestController extends \RightNow\Controllers\Base
{
	function __construct() { parent::__construct(); }
	
	function Test()
	{
		try{
			echo "THIS IS A TEST. NOBODY PANIC!";
			throw new Exception();
			echo "I shouldn't be here";
		}
		catch(Exception $e){
			echo "Catch";
		}
	}
} 
        

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!