try catch with Coldbox Exceptions

HI have the following in one of my controllers:

`
try {

uploadedFile = getPlugin(“FileUtils”).uploadFile(fileField=“bannerImage”,destination=expandPath(‘public/#prc.org.getID()#/website/banner’),accept=“image/jpg,image/png,image/gif”);

} catch(excType excVar) {

event.renderData(‘json’,response);

}
`

If I upload a PDF (which is not in the ‘accept’ list, I just get a standard exception error:

**Error Messages:**The MIME type or the Extension of the uploaded file application/pdf was not accepted by the server.
Only files of type image/jpg,image/png,image/gif can be uploaded. Verify that you are uploading a file of the appropriate type.

It seems that the try catch is being ignored?

So I guess my main question is, how do I intercept the file upload if the user uploads an unaccepted file type?

Second, does try/catch work with coldbox exceptions? If not, how should I catch them in my code (without relying on global exception handlers).

Many Thanks!

Jason

That’s because you’re only catching exceptions of type excType. Change your catch to (any excVar) and it should start catching them. And to answer your question, ColdBox exceptions are just regular old ColdFusion exceptions that are thrown.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Brad,

Do you know where a list of the catch types might be found, I have searched a number of times in the ColdFusion documentation and haven’t yet found anything.

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_c_04.html

  • application: catches application exceptions
  • database: catches database exceptions
  • template: catches ColdFusion page exceptions
  • security: catches security exceptions
  • object: catches object exceptions
  • missingInclude: catches missing include file exceptions
  • expression: catches expression exceptions
  • lock: catches lock exceptions
  • custom_type: catches the specified custom exception type that is defined in a cfthrow tag
  • searchengine: catches Verity search engine exceptions
  • any: catches all exception types

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Brad. Spot on. Thank you!!