1

I was wondering if I can assign $e->getMessage() to a vaiable like so:

$errmsg = $e->getMessage();

I'm trying to mail() it to myself whenever an exception is caught from a try catch block and don't wanna screw up the mail body...

3
  • 1
    Yes, you can do it. Commented Dec 13, 2016 at 18:42
  • ty sir, wanted extra confirmation before I deploy the code Commented Dec 13, 2016 at 18:46
  • So you can't just try it yourself? Commented Dec 13, 2016 at 18:47

1 Answer 1

1

Sure :

$msg = 'foo';
try{
    throw new Exception('bar');
}catch (Exception $e){
    $msg = $e->getMessage();
}

echo $msg; // bar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.