I'm trying to build an user-made exception, I have the following code:
class CalcError extends Exception
{
function __construct($message)
{
parent::Exception($message);
}
}
try {
$i=2;
if ($i==1)
{
throw new Exception ( 'Unknown error', 501);
}
else
{
throw new CalcError("Message");
}
} catch (CalcError $c) {
print 'message: '.$c->getMessage();
}
catch (Exception $e) {
print 'message: '.$e->getMessage();
}
(The $i=2 was just made to check that a general exception is correctly thrown).
But for some reason it doesn't throw my defined exception. In fact, the script fails to continue executing,I've checked the code a lot and I don't understand what can fail.
Any idea? Thanks in advance.
class CalcError extends Exception
{
function __construct($message)
{
parent::Exception($message);
}
}
try {
$i=2;
if ($i==1)
{
throw new Exception ( 'Unknown error', 501);
}
else
{
throw new CalcError("Message");
}
} catch (CalcError $c) {
print 'message: '.$c->getMessage();
}
catch (Exception $e) {
print 'message: '.$e->getMessage();
}
(The $i=2 was just made to check that a general exception is correctly thrown).
But for some reason it doesn't throw my defined exception. In fact, the script fails to continue executing,I've checked the code a lot and I don't understand what can fail.
Any idea? Thanks in advance.