Why isn't my catch block not works while passing LINUX command in email?

I have some code that looks like this

  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;
}

now when i passing email that contains any LINUX commands like scp, rcp, ssh then catch block not executed

if i passed email like

  • test@gmail.com

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

if I passed email like

  • ssh.test@gmail.com

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

I am not sure why catch block not getting worked with LINUX commands in email? Please help...

Answers


I think probably your class is namespaced, if so you need to root out the Exception class you are catching for:

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

By adding \ in front of it, or it looks for namespace\Exception by default.

I'm just guessing that based on how you throw the exception

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

You wouldn't need to use \Exception if your class wasn't namespaced. You could do Exception instead.

Cheers!

One last thing, the code you put is totally invalid:

  try{ 
   ...
  }

  static function checkEmailExist(){
  ...
  }

To me this says:

 <?php
   namespace somename;
  class someclass{


        try{ 
         ...
        }

        static function checkEmailExist(){
        ...
        }


 }

In which place you cant put that try block there. But maybe it's not really like that and what you posted is a simplification?


Need Your Help

Registering an ELB to an ECS service with random host port

amazon-web-services docker amazon-elb

I'm working with the ECS service on AWS and I have this problem - the docker containers I need to run on ECS are webservices, each container should have its internal port 80 mapped to a random port...

TypeScript for ... of with index / key?

for-loop foreach typescript

As described here TypeScript introduces a foreach loop: