use try/catch and still call the Main.OnException method

Is there any way to run try and catch around a process and still force coldbox into the Main.OnException method if there is an error?

Have you tried cfrethrow?

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

I will give that a try - thanks!

For what I am trying to do, this unfortunately won’t work. I guess I am trying to have my cake and eat it too. I want to be able to return a suitable error message in JSON to a requestor while at the same time being able to use the email logger called in the onException method to send the pretty html bug report generated by coldfusion. Using rethrow is causing the issue I had before in that the requestor is expecting json and instead gets the coldfusion exception (which isn’t in JSON). I tried a custom error handler, but don’t have access to the exception bean/bug report which has the data I want to send to the developer.

In onExpection(), you will receive rc.exceptionBean. You can use serializeJSON() to convert ColdFusion exception to JSON format.
Also, see http://apidocs.ortussolutions.com/coldbox/4.2.0/index.html. Search for ExceptionBean.

Thanks for you help with this, but it the same issue still occurs. The return message to the requestor is in html unless I run a try/catch, but that blocks getting the full error logging since the exception bean is not yet available. What I am trying to do may not be feasible.

Hi

Here is the examples how coldbox can return json formatted error messages

https://github.com/coldbox-templates/rest

Thank you for the information, Sana.

What version of ColdBox are you using?

You can log the error yourself before returning JSON to the user. You should also be able to return JSON in your custom error template if you want. You’d probably need to detect if the request was for AJAX or not.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Assumed log error is configured to send email. You can log error and output it as JSON in onException()
log.error( rc.exceptionBean.getMessage(), rc.exceptionBean.getMemento() );

event.renderData( type=“json”, data=rc.exceptionBean.getExceptionStruct() );