[TYPO3-mvc] How to catch the exceptions???

Franz Koch typo3.RemoveForMessage at elements-net.de
Thu Sep 2 13:43:41 CEST 2010


Hey,

> Extbase is so nice, it even throws exceptions at us :)
>
> What I don't understand is how to catch those Exceptions :)
>
> For example:
> public function showAction(Tx_BwShop_Domain_Model_Product $product) {
>
> }
>
> If in the url we have product= something that doesn't exist extbase will
> throw this exception:
>
> Tx_Extbase_MVC_Exception_InvalidArgumentValue
>
> The value must be of type "Tx_BwShop_Domain_Model_Product", but was of
> type "NULL".
>
> How can I catch this exception and show a meaningful explanation to the
> user???

how about allowing the product to be NULL and catch this inside your 
method? That's how I do it.

public function showAction(Tx_BwShop_Domain_Model_Product $product = NULL) {
   if ($product === NULL) {
	$this->forward('invalidProduct');
	break;
   }
   // do your regular stuff here
}

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list