How to generate and catch custom exceptions

Hello!

I need to generate and catch custom exceptions in application component. I have TestComponent :


<?php

class TestComponent extends CApplicationComponent {


  public function __construct() {

    $a=false;

    if ($a) {


    } else

      throw new CTestException("Test exception!");

  }

}


class CTestException extends CException {}

Have a controller trying to catch it :


class TestController extends CController {


  public function actionTesting() {

    try {

      $testcomponent = new TestComponent();

      } catch(CTestException $e) {

      echo $e->getMessage();

    }

  }

After calling "http://localhost/test/testing" - nothing displayed. But if I throw general CException - everything works, "Test exception!" displayed :


<?php

class TestComponent extends CApplicationComponent {


  public function __construct() {

    $a=false;

    if ($a) {


    } else

      throw new CException("Test exception!");

  }

}




class TestController extends CController {


  public function actionTesting() {

    try {

      $testcomponent = new TestComponent();

      } catch(CException $e) {

      echo $e->getMessage();

    }

  }

No error message, it just doesn’t catch the custom exception?

Pasted your controller action into a 1.1.4-generated site controller. Added TestComponent.php to protected/components.

Works for me!

PHP 5.3.3 on Linux

/Tommy