Modifying my answer in light of finding out it's Magento 1.x
It would be helpful for you to show us the actual output of you error however you are catching the error effectively.
Have you tried putting a die into your catch ?
How is your exception being thrown ?
What is the contents logMessage() method.
It really should just be as simple as doing the following :
public function testAction() {
try {
error();
} catch(Exception $exception) {
Mage::log($e, null, 'my-custom-file.log', true);
}
}
You could also try catching the error this way
public function testAction() {
try {
error();
} catch (Mage_Core_Exception $e) {
Mage::log($e, null, 'my-custom-file.log', true);
} catch(Exception $exception) {
Mage::log($e, null, 'my-custom-file.log', true);
}
}
As the semantics would suggest you can only catch an error that has been thrown. You can't catch a fatal error.
Using your question as an example :
public function testAction() {
try {
$this->doingSomething();
} catch(Exception $exception) {
Mage::log($e, null, 'my-custom-file.log', true);
}
}
protected function doSomething() {
if (!method_exists($this, 'error') {
Mage::throwException('Method error() is not defined');
} else {
return true;
}
}