doujiao1984 2010-07-29 15:19
浏览 52
已采纳

处理异常 - 致命错误:未捕获的异常'EppCommandsExceptions',消息'命令语法错误'

Fatal error: Uncaught exception 'EppCommandsExceptions' 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

  • 写回答

1条回答 默认 最新

  • doue9730 2010-07-29 15:24
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备