Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[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
0683p000009MBsB.png
Labels (4)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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.
0683p000009MBo3.png
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 0683p000009MACn.png

View solution in original post

6 Replies
Anonymous
Not applicable
Author

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
Dezzsoke
Contributor III
Contributor III

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

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.
Anonymous
Not applicable
Author

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. 
Anonymous
Not applicable
Author

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.
0683p000009MBo3.png
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 0683p000009MACn.png
Anonymous
Not applicable
Author

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