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();
}
}