3

I am following this post to convert CSV and I am getting java.lang.OutOfMemoryError error when records are GT > 7k.

CFTRY/CFCATCH blocks are not able to catch this as this is an error not exception.

So, is there any way to catch this error inside the function from which caused this error rather than using onError method of Application.cfc?

I understand that we can increase heap size.

Please help. Thanks in advance.

Community
  • 1
  • 1
Abhishekh Gupta
  • 6,206
  • 4
  • 18
  • 46
  • 2
    [You should never catch an Error](http://stackoverflow.com/a/11018879/1686291) !! – Not a bug Mar 17 '15 at 08:42
  • Agreed. Error's indicate a serious problem that it is unlikely the application can handle anyway. That is probably the reason [try/catch does not capture Errors](http://stackoverflow.com/questions/14237283/coldfusion-not-catching-noclassdeffounderror/14243560#14243560). What are you ultimately trying to do: import/export from a db? If so, most databases provide tools for bulk importing/exporting that do a much better job. – Leigh Mar 17 '15 at 16:39
  • @Leigh I am getting this error when I am trying to do some manipulations on the array returned by `csvToArray()`. But want to catch this error in the function which caused this as I have to set one flag in DB. Otherwise I have to do this operation in `onError` method. So I was thinking that if it might be possible to catch this in function itself. – Abhishekh Gupta Mar 17 '15 at 17:05
  • @Beginner - I understand, but that does not really answer the question. ie What the overall goal here: db import, export, ...? As far as the error goes, it is as you suspected: you cannot catch it. An `Error` means there something really wrong. Often there is nothing you can do once it occurs, so they are not really meant to be caught. In terms of "error handling", your only option is using `onError`. – Leigh Mar 17 '15 at 17:48
  • Yes, `onError` is only hope :( . I am exporting to DB. – Abhishekh Gupta Mar 17 '15 at 17:55
  • You mean loading a csv into a db? Have you looked into your dbms tools? Not sure which one you are using, but most provide tools for bulk loading or exporting. Generally, those are *much* better suited for the job. – Leigh Mar 17 '15 at 18:18
  • I am not simply exporting CSV to DB. There are many operation behind it. – Abhishekh Gupta Mar 17 '15 at 18:34
  • 1
    This is probably a conversation for another thread, but .. if you mean importing a CSV *into* your database, that sounds like a good use for a staging table. Import the csv into the staging table, manipulate the data, then `insert` it into the final table. That is the approach I prefer, as it has several advantages (performance, data integrity, etcetera..). Hard to say more without knowing anything about the process. – Leigh Mar 17 '15 at 19:26
  • Since the question/answer is essentially the same as: [ColdFusion not catching NoClassDefFoundError](http://stackoverflow.com/questions/14237283/coldfusion-not-catching-noclassdeffounderror), voting to close as a duplicate. – Leigh Mar 17 '15 at 19:56

0 Answers0