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

39 views
Skip to first unread message

sgood2000

unread,
Aug 31, 2016, 10:54:06 PM8/31/16
to ColdBox Platform
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?

Ancient Programmer

unread,
Aug 31, 2016, 11:06:39 PM8/31/16
to ColdBox Platform
Have you tried cfrethrow?

br...@bradwood.com

unread,
Aug 31, 2016, 11:17:23 PM8/31/16
to col...@googlegroups.com
<cfrethrow>

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: br...@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com 
 
 
--------- Original Message ---------
--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/c07b98fc-72a6-4220-99be-4689e3f87815%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sgood2000

unread,
Sep 2, 2016, 12:48:04 AM9/2/16
to ColdBox Platform
I will give that a try - thanks!

On Wednesday, August 31, 2016 at 11:06:39 PM UTC-4, Ancient Programmer wrote:
Have you tried cfrethrow?

sgood2000

unread,
Sep 2, 2016, 9:00:19 AM9/2/16
to ColdBox Platform
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.

Ancient Programmer

unread,
Sep 2, 2016, 9:39:17 AM9/2/16
to ColdBox Platform
In onExpection(), you will receive rc.exceptionBean. You can use serializeJSON() to convert ColdFusion exception to JSON format.

sgood2000

unread,
Sep 2, 2016, 10:14:09 AM9/2/16
to ColdBox Platform
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.

Sana Ullah

unread,
Sep 2, 2016, 10:18:50 AM9/2/16
to col...@googlegroups.com
Hi

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


Warm Regards
Sana

--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+unsubscribe@googlegroups.com.

To post to this group, send email to col...@googlegroups.com.

sgood2000

unread,
Sep 2, 2016, 4:10:57 PM9/2/16
to ColdBox Platform
Thank you for the information, Sana.

Warm Regards
Sana

To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.

To post to this group, send email to col...@googlegroups.com.

br...@bradwood.com

unread,
Sep 2, 2016, 5:24:36 PM9/2/16
to col...@googlegroups.com
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: br...@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com 
 
 
--------- Original Message ---------
--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.

Ancient Programmer

unread,
Sep 2, 2016, 7:19:30 PM9/2/16
to ColdBox Platform
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() );




On Friday, September 2, 2016 at 6:00:19 AM UTC-7, sgood2000 wrote:
Reply all
Reply to author
Forward
0 new messages