[resolved] Catch Java Exception tFileCopy

One Star

[resolved] Catch Java Exception tFileCopy

Hi everybody,
I am getting a trouble using Talend :
I am copy/pasting XML file with the component tFileCopy.
The Destination Repertory and the PATH to the file are given with a row main linked to the tFileCopy.
I have actually no trouble when the file exist, it's working fine.
But if the file don't exist, i am getting a Java Exception, that is actually normal.
But i don't want that the Job stop because of that.
That's why I am trying to catch the error with a tWarn.
The error is catch, I have the row passing in tWarn, but I still have my Java Exception, and the job stop.
How can I do to catch the Exception without stopping the Job ?
I tried to use a java class :
File f = new File("%PATH_TO_FILE%");
if ( f.exists() ) {}  

But actually I don't know how to use it ( I have to add something in the routine, but I don't know how/what to include ).
Is there an other way to do what I want ?
Thanks for watching,
regards,
Mathis

Accepted Solutions
One Star

Re: [resolved] Catch Java Exception tFileCopy

Thank you all for your answer.
I took a bit of each, and i solved my problem.
I am using a tJavaRow to assign the context variable, a tFlowToIterate to change the flux to an Iterate,
a tFileExist to check if the File is here, and the row IF to copy the file, or to write an error log in my database.

Here is the code in the tjavaRow : 
context.dirname=input_row.dirname;
context.NOM_FIC_XML=input_row.NOM_FIC_XML;
output_row.pathtoxml=input_row.dirname+"/"+input_row.NOM_FIC_XML;


Here is the NameofFileField in my tFileExist_1 :
context.dirname+"/"+context.NOM_FIC_XML

and the condition IF linked to the tFileCopy_1: 
((Boolean)globalMap.get("tFileExist_1_EXISTS"))


Problem solved, thank you all Smiley Happy

All Replies
Four Stars

Re: [resolved] Catch Java Exception tFileCopy

Hi Mathis,
- Next to tUniqRow, use tjavarow and save the file name in the context variable
- use iterate link from tjavarow to connect to tFileCopy...
When you do this, if there is no row, then iterate will not work and you need not manage exceptions...
Try this way.
Vaibhav
Five Stars

Re: [resolved] Catch Java Exception tFileCopy

Put down a tFlowToIterate followed by a tJavaFlex:
Begin:
try {
end:
} catch (Exception ex) {
 System.out.println(ex.getLocalizedMessage());
}
One Star

Re: [resolved] Catch Java Exception tFileCopy

I am trying the solution of Vaibhav,
but I still don't know which routine does I have to add in my job.
File f = new File(input_row.dirname+"/"+input_row.NOM_FIC_XML);
if ( f.exists() ) {  
context.dirname=input_row.dirname;
context.NOM_FIC_XML=input_row.NOM_FIC_XML;
}

If i am using this code i have an error :

File isn't recognize as a valid type


I think that's because I didn't add a routine for the type File, but I don't know where to find it.
Five Stars

Re: [resolved] Catch Java Exception tFileCopy

can you try tFileExist component with "if" connector. I think this will also work.
after tunique row component use tFileExist and then use "IF" connectors to check whether file is exist or not. 
One Star

Re: [resolved] Catch Java Exception tFileCopy

Thank you all for your answer.
I took a bit of each, and i solved my problem.
I am using a tJavaRow to assign the context variable, a tFlowToIterate to change the flux to an Iterate,
a tFileExist to check if the File is here, and the row IF to copy the file, or to write an error log in my database.

Here is the code in the tjavaRow : 
context.dirname=input_row.dirname;
context.NOM_FIC_XML=input_row.NOM_FIC_XML;
output_row.pathtoxml=input_row.dirname+"/"+input_row.NOM_FIC_XML;


Here is the NameofFileField in my tFileExist_1 :
context.dirname+"/"+context.NOM_FIC_XML

and the condition IF linked to the tFileCopy_1: 
((Boolean)globalMap.get("tFileExist_1_EXISTS"))


Problem solved, thank you all Smiley Happy
Four Stars

Re: [resolved] Catch Java Exception tFileCopy

Great!!! 
Thanks for updating the solution here..
Vaibhav