Answers.Body: <p>What you can do is call <code>CRM_Core_Error::backtrace('some message', TRUE);</code> before you throw the exception to get it to appear in the Civi log.</p>
  <p>It might also work if you throw a regular \Exception instead of CRM_Core_Exception then it might end up in the web server log. But Civi API calls generally get caught and reformatted and then sent back to the caller (in this case js, hence they appear as js errors).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-15T04:04:57.550Z
Answers.Text: Thank you - very helpful!
Answers.UserDisplayName: Aaron
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-09-13T16:04:15.710Z
Answers.LastActivityDate: 2021-09-13T16:04:15.710Z
Answers.UserDisplayName: Demerit
Body: <p>I'm working on some code that should fail quickly and loudly if things go wrong. It's part of the mailer and called via the API by the mailing create pages.</p>
  <p>But I can't get the exception to end up in the log (with a stack trace hopefully!)</p>
  <p>Surprisingly both SQL errors and the CRM_Core_Exception I'm throwing end up in the JS console!</p>
  <p>Is there a setting to change this behavior? I don't see one under the debugging settings.</p>
  <p>Thanks!</p>
  
Tags: <civimail>
Title: Exceptions returned to the API caller and displayed in the JS console
ThreadText: # Exceptions returned to the API caller and displayed in the JS console
  
  (Asked by: username_0 on 2021-09-13)
  
  I'm working on some code that should fail quickly and loudly if things go wrong. It's part of the mailer and called via the API by the mailing create pages.
  
  But I can't get the exception to end up in the log (with a stack trace hopefully!)
  
  Surprisingly both SQL errors and the CRM\_Core\_Exception I'm throwing end up in the JS console!
  
  Is there a setting to change this behavior? I don't see one under the debugging settings.
  
  Thanks!
  
  **Tags:** civimail
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-09-13. Score: 1 | Accepted answer
  
  What you can do is call `CRM_Core_Error::backtrace('some message', TRUE);` before you throw the exception to get it to appear in the Civi log.
  
  It might also work if you throw a regular \Exception instead of CRM\_Core\_Exception then it might end up in the web server log. But Civi API calls generally get caught and reformatted and then sent back to the caller (in this case js, hence they appear as js errors).
  
  > **Comments:**
  > **username_0**: Thank you - very helpful!  
  
  ---
  
  