gpt4 book ai didi

php - 为什么在电子邮件中传递 LINUX 命令时我的 catch block 不起作用?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:23:21 26 4
gpt4 key购买 nike

我有一些看起来像这样的代码

  try
{
$emailObj->checkEmailExist($emailid);
}
catch(Exception $e)
{
echo 'Insert Record.';
$emailObj->addEmail($emailid);
}

static function checkEmailExist($emailID)
{
$rowset = $this->_tableGateway->select(array('user_email_id'=>$emailID));
$row = $rowset->current();
}
if (!$row) {
throw new \Exception("Could not find data for email : $emailID",404);
}
return $row;
}

现在,当我传递包含任何 LINUX 命令(如 scp、rcp、ssh)的电子邮件时,catch block 不会执行

如果我像这样传递电子邮件

  • test@gmail.com

it check if exist or not, if not then insert email

如果我像这样传递电子邮件

  • ssh.test@gmail.com

it stops execution with throw an exception, even email not exist - Insert function not executed.

我不确定为什么 catch block 无法在电子邮件中使用 LINUX 命令?请帮助...

最佳答案

我想你的类可能是命名空间的,如果是这样你需要根除你正在捕获的异常类:

try
{
$emailObj->checkEmailExist($emailid);
}
catch(\Exception $e)
{
echo 'Insert Record.';
$emailObj->addEmail($emailid);
}

通过在其前面添加\,或者默认查找namespace\Exception

我只是根据你抛出异常的方式来猜测

throw new \Exception("Could not find data for email : $emailID",404);

如果您的类没有命名空间,则不需要使用 \Exception。您可以改为执行 Exception

干杯!

最后一件事,您输入的代码完全无效:

  try{ 
...
}

static function checkEmailExist(){
...
}

这对我来说是这样的:

 <?php
namespace somename;
class someclass{


try{
...
}

static function checkEmailExist(){
...
}


}

在什么地方你不能把那个 try block 放在那里。但也许事实并非如此,您发布的只是一种简化?

关于php - 为什么在电子邮件中传递 LINUX 命令时我的 catch block 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39609694/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com