Catch and re-throw java errors in a tLogCatcher

One Star

Catch and re-throw java errors in a tLogCatcher

In my job architecture, I place a tLogCatcher in my jobs (screen shot attached). When errors are caught by the tLogCatcher , I then log these errors to a database message table. I also output to stats and log files. For the most part this works fine However, if I leave "Catch Java Exception" unchecked in tLogCatcher , I cannot log java errors to my database table - they do appear in the log file. if I leave check the "Catch Java Exception" option, java errors do not appear in the log file - they do appear in the database table. I want the java errors to appear in BOTH the database table and log file.
So, my question is, is there a way to check the "Catch Java Exception" option in tLogCatcher, then continue with the tLogCatcher flow in my screen shot (logs to database table), and then "rethrow" the error - Ex. throw the error to another tLogCatcher, which has the "Catch Java Exception" option unchecked?
Dave
Community Manager

Re: Catch and re-throw java errors in a tLogCatcher

Hello
Where do you log the exception into the file?
Anyway, if you unchec the 'catch jave exception' box on tLogCatcher component, it don't catch any java exception and log them into database. In your case, If you want to log the exception message both into database and file, you can use tReplicate to replicate the row many time as need.
For example:
tLogCatcher---treplicate---tOracleOutput
|
tFileOutputDelimited

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Catch and re-throw java errors in a tLogCatcher

Hello
Where do you log the exception into the file?
Anyway, if you unchec the 'catch jave exception' box on tLogCatcher component, it don't catch any java exception and log them into database. In your case, If you want to log the exception message both into database and file, you can use tReplicate to replicate the row many time as need.
For example:
tLogCatcher---treplicate---tOracleOutput
|
tFileOutputDelimited

Best regards
Shong

Hi shong,
In project settings, I define stats and log output - that works great (see new screen shot). Your treplicate solution looks interesting - I will try that as well.
Shong - I found a reproduceable bug. This occurs whether "catch java exceptions" is checked or un-checked. If an exception is caught above in the tLogCatcher, and then tOracleOutput fails because it CANNOT connect to the database, then the original error is lost, and it does not get output to the file system log file. However, If an exception is caught above in the tLogCatcher, and then tOracleOutput fails AFTER it connect to the database (causes an oracle exception during the dml operation, for example), then the original error is NOT lost, and it does get output to the file system log file.
I can reproduce this bug every time - maybe your tReplicate will be a workaround to it - will try that.
One Star

Re: Catch and re-throw java errors in a tLogCatcher

Hello
Where do you log the exception into the file?
Anyway, if you unchec the 'catch jave exception' box on tLogCatcher component, it don't catch any java exception and log them into database. In your case, If you want to log the exception message both into database and file, you can use tReplicate to replicate the row many time as need.
For example:
tLogCatcher---treplicate---tOracleOutput
|
tFileOutputDelimited

Best regards
Shong

Shong,
I replied twice to this (your reply), so please read both of my replies. This reply is for the results of using tReplicate to a tFileOutputDelimited. As long as the tFileOutputDelimited is first in order precedence (main) , prior to tOracleOutput, your solution works great,
Thanks!

See attached screen shot .
Dave
One Star

Re: Catch and re-throw java errors in a tLogCatcher

Hi Dadumas,
Cud u tell me wat have u written in ur tJavaFlex and tOracleRow component to log exceptions in Databasetable.
One Star

Re: Catch and re-throw java errors in a tLogCatcher

Hi Dadumas,
Cud u tell me wat have u written in ur tJavaFlex and tOracleRow component to log exceptions in Databasetable.

Sure. For the database , I have an ETL framework that I have used for years, not just for Talend - logs meta data throughout the job. Part of that is a message log table.
Take a look at the screen shot, and then...
In the tJavaFlex:
context.SuccessFlag = 0;
context.Message = "For last Message: " + context.Message + ", Failure, in tLogCatcher, job failed, see message log for details, ERROR: "
+ row5.message;
row5.Message is the error message coming from tLogCatcher.
Then in the tOracleRow:
"
INSERT INTO STGETLMESSAGELOG
(LOGID,
JOBID,
JOBRUNID,
CREATEDDATE,
MESSAGE,
SUCCESSFLAG,
PROCESSNAME,
SUBPROCESSNAME)
VALUES
(STGETLLOGSEQ.NEXTVAL,"
+ context.VPJobId + ","
+ context.JobRunId + ","
+ "TO_DATE(" + "'" + TalendDate.getDate("MM-DD-CCYY hh:mm:ss") + "'" + "," + "'" + "MM-DD-YYYY hh24:mi:ss" + "'" + "),"
+ "'" + context.Message + "'" + ","
+ context.SuccessFlag + ","
+ "'" + context.ProcessName + "'" + ","
+ "'" + context.SubProcessName + "'"
+ ")"
Hope this helps.
Dave