One Star

System.Exit()

Hello,
I'd like to manage several different exit code in my job. I'd like to exit my job with code 1 if no file, with code 2 if the file contains less than 2 lines, etc...
I can exit my job by typing:
System.exit(2);
It works.
But, as soon as I try to put the exit code in variable:
Integer myErrorCode = 2;
System.exit(myErrorCode);
It does not work... The error is:
Exception in component tJava_1
java.lang.NullPointerException
Any idea ? Does anyone of you try this ???
Thank you for your help.
Arnaud
5 REPLIES
One Star

Re: System.Exit()

Sorry, I don't know what happened, but I've juste retried and .... it works !
The demo effect...
Arnaud
Seventeen Stars

Re: System.Exit()

hi,
i'm not a 'pro in java' but some precision about exit method :
I'd like to exit my job with code

but exit() method is more than just exit the job
Terminates the currently running Java Virtual Machine
...
The call System.exit(n) is effectively equivalent to the call:
Runtime.getRuntime().exit(n)

I know that i 've had some "suprises" first times I have use it ...
One Star

Re: System.Exit()

Hi Arnaud,
using System.exit() in Java is mostly a bad solution. This will, as kzone mentioned, immediately terminate the JVM.
The bad point is that I don't know how to do it right. There is a global static variable called errorCode which value is passed to the caller but I think setting its value will not stop processing and may be overwritten at a later time.
Will someone of the Talend team have a good answer? May we create a feature request for a special function?
Bye
Volker
Employee

Re: System.Exit()

Hello,
tDie allow you to finish your job with an error X configurable in the component properties.
Am I missing something ?
HTH
One Star

Re: System.Exit()

Thanks Michaël!
Yes, I've forgotten this component :-(
I only did look for a solution to cancel a script within an own function (because we talked about java code).
@Arnaud: Will this help you?
Bye
Volker