开发者

Handling Exceptions - Fatal error: Uncaught exception 'EppCommandsExceptions' with message 'Command syntax error'

Fatal error: Uncaught exception 'EppCommandsExcept开发者_JAVA百科ions' with message 'Required parameter missing'

The line in question:

throw new EppCommandsExceptions($result->msg, $codigo); 

Why am I having this error on this line?

On EppCommandsExceptions.class.php I have this class that extends Exception:

class EppCommandsExceptions extends Exception
{
    //could be empty.
}

Next, on CommandsController.php I have:

include_once('EppCommandsExceptions.class.php');

and, later, if something bad happens on method1:

throw new EppCommandsExceptions($result->msg, $codigo);

later, on this same controller, another method2 that will run after method1, I have: if something goes bad with this too:

throw new EppCommandsExceptions($result->msg, $codigo);

Later I have, for the contact part - method1

try
{
    $createdContact = $comandos->createContact($contactoVo);
}
catch(EppCommandsExceptions $e)
{
    $error .= 'Error Contact. Cód:'.$e->getCode().' Mensagem:'.$e->getMessage();
}

And later, for domain part: method2

try
{
    $createdDomain = $comandos->createDomain($domainVo);
}
catch(EppCommandsExceptions $e)
{
    $error .= 'Error Domain. Cód:'.$e->getCode().' Mensagem:'.$e->getMessage();
}

Is it because I'm using the same exception for both methods? Should I have one Exception class for EACH method? :s

Please advice, Thanks a lot. MEM


The exception you throw will only be caught if it's inside a try block.

If it isn't it'll propagate up the call stack, until it is caught in one of the earlier calling functions.

You're getting that fatal error because the exception you throw is never caught, so it's handled by the default unhandled exceptions handler, which emits the fatal error.

Examples:

try
{
    $createdContact = $comandos->createContact($contactoVo);
    if (error_condition())
        throw new EppCommandsExceptions $e;
}
catch(EppCommandsExceptions $e)
{
    $error .= 'Error Contact. Cód:'.$e->getCode().' Mensagem:'.$e->getMessage();
}

Throwing the exception directly in the try block is not usually very useful, because you could just as well recover from the error condition directly instead of throwing an exception. This construct becomes more useful, though, if createContact may throw an exception. In this case, you have at some point to catch EppCommandsExceptions to avoid a fatal error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜