<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Catch Java Exceptions in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Catch-Java-Exceptions/m-p/2372193#M135056</link>
    <description>Hello all, 
&lt;BR /&gt;I desperately try to get a Java (SQL) Exception to be caught by Talend. 
&lt;BR /&gt;I read many posts which say "easy, just put a tLogCatcher". Of course, that won't work... 
&lt;BR /&gt;I tried about anything, without luck (and this should be soooo trivial). 
&lt;BR /&gt;(see picture) 
&lt;BR /&gt;I want to catch any exception/tDie... 
&lt;BR /&gt;This leads to a tJavaRow which uses a message I build with a tMap to put it in a context variable (context.rejectedMessages; String) and sets another context variable to specify it failed. 
&lt;BR /&gt; 
&lt;PRE&gt;context.isRejected = true;&lt;BR /&gt;context.rejectedMessages += input_row.message;&lt;/PRE&gt; 
&lt;BR /&gt;I tried with a 
&lt;BR /&gt; - tLogCatcher : catches all it can (Java Exception, tDie, tWarn); When I debug, the message in TalendException.printStackTrace() is not there when the component is looped for its messages (???) 
&lt;BR /&gt;(from the generated code) 
&lt;BR /&gt; 
&lt;PRE&gt;	private class TalendException extends Exception {&lt;BR /&gt;		private java.util.Map&amp;lt;String, Object&amp;gt; globalMap = null;&lt;BR /&gt;		private Exception e = null;&lt;BR /&gt;		private String currentComponent = null;&lt;BR /&gt;		private TalendException(Exception e, String errorComponent,&lt;BR /&gt;				final java.util.Map&amp;lt;String, Object&amp;gt; globalMap) {&lt;BR /&gt;			this.currentComponent = errorComponent;&lt;BR /&gt;			this.globalMap = globalMap;&lt;BR /&gt;			this.e = e;&lt;BR /&gt;		}&lt;BR /&gt;		@Override&lt;BR /&gt;		public void printStackTrace() {&lt;BR /&gt;			if (!(e instanceof TalendException || e instanceof TDieException)) {&lt;BR /&gt;				globalMap.put(currentComponent + "_ERROR_MESSAGE", e&lt;BR /&gt;						.getMessage());&lt;BR /&gt;				System.err&lt;BR /&gt;						.println("Exception in component " + currentComponent);&lt;BR /&gt;			}&lt;BR /&gt;			if (!(e instanceof TDieException)) {&lt;BR /&gt;				if (e instanceof TalendException) {&lt;BR /&gt;					e.printStackTrace();&lt;BR /&gt;				} else {&lt;BR /&gt;					e.printStackTrace();&lt;BR /&gt;					e.printStackTrace(errorMessagePS);&lt;BR /&gt;				}&lt;BR /&gt;			}&lt;BR /&gt;			if (!(e instanceof TalendException)) {&lt;BR /&gt;				try {&lt;BR /&gt;					for (java.lang.reflect.Method m : this.getClass()&lt;BR /&gt;							.getEnclosingClass().getMethods()) {&lt;BR /&gt;						if (m.getName().compareTo(currentComponent + "_error") == 0) {&lt;BR /&gt;							m.invoke(TX_SPAccoContractSupplements2TOST90.this,&lt;BR /&gt;									new Object[] { e, currentComponent,&lt;BR /&gt;											globalMap });&lt;BR /&gt;							break;&lt;BR /&gt;						}&lt;BR /&gt;					}&lt;BR /&gt;					if (!(e instanceof TDieException)) {&lt;BR /&gt;						tLogCatcher_1.addMessage("Java Exception",&lt;BR /&gt;								currentComponent, 6, e.getClass().getName()&lt;BR /&gt;										+ ":" + e.getMessage(), 1);&lt;BR /&gt;						tLogCatcher_1Process(globalMap);&lt;BR /&gt;					}&lt;BR /&gt;				} catch (java.lang.SecurityException e) {&lt;BR /&gt;					this.e.printStackTrace();&lt;BR /&gt;				} catch (java.lang.IllegalArgumentException e) {&lt;BR /&gt;					this.e.printStackTrace();&lt;BR /&gt;				} catch (java.lang.IllegalAccessException e) {&lt;BR /&gt;					this.e.printStackTrace();&lt;BR /&gt;				} catch (java.lang.reflect.InvocationTargetException e) {&lt;BR /&gt;					this.e.printStackTrace();&lt;BR /&gt;				} catch (TalendException e) {&lt;BR /&gt;					// do nothing&lt;BR /&gt;				}&lt;BR /&gt;			}&lt;BR /&gt;		}&lt;BR /&gt;	}&lt;/PRE&gt; 
&lt;BR /&gt;It enters the first "if" and prints out the exception trace; then it enters the "if (!(e instanceof TalendException)) " , finds the "_error" method and runs it; 
&lt;BR /&gt;then in "if (!(e instanceof TDieException))" it adds the java exception ("tLogCatcher_1.addMessage(....)"). Pretty cool, huh. 
&lt;BR /&gt;But at the next line ("tLogCatcher_1Process(globalMap);"), no message is found in this method's loop ==&amp;gt; nothing gets fired :'( 
&lt;BR /&gt; - a PostJob tJava which checks for globalMap.get("xxxx_ERROR_MESSAGE") without any luck : 
&lt;BR /&gt; 
&lt;PRE&gt;//check for errors... once again it is hardcoded...&lt;BR /&gt;if (globalMap.get("tPrejob_1_ERROR_MESSAGE") != null) {&lt;BR /&gt;	context.isRejected = true;&lt;BR /&gt;	context.rejectedMessages += "\n" + (String)globalMap.get("tPrejob_1_ERROR_MESSAGE");		&lt;BR /&gt;}&lt;BR /&gt;if (globalMap.get("tMSSqlConnection_1_ERROR_MESSAGE") != null) {&lt;BR /&gt;	context.isRejected = true;&lt;BR /&gt;	context.rejectedMessages += "\n" + (String)globalMap.get("tMSSqlConnection_1_ERROR_MESSAGE");		&lt;BR /&gt;}&lt;BR /&gt;if (globalMap.get("tDB2Connection_1_ERROR_MESSAGE") != null) {&lt;BR /&gt;	context.isRejected = true;&lt;BR /&gt;	context.rejectedMessages += "\n" + (String)globalMap.get("tDB2Connection_1_ERROR_MESSAGE");		&lt;BR /&gt;}&lt;BR /&gt;if (globalMap.get("tMSSqlInput_1_ERROR_MESSAGE") != null) {&lt;BR /&gt;	context.isRejected = true;&lt;BR /&gt;	context.rejectedMessages += "\n" + (String)globalMap.get("tMSSqlInput_1_ERROR_MESSAGE");		&lt;BR /&gt;}&lt;BR /&gt;if (globalMap.get("tDB2Output_1_ERROR_MESSAGE") != null) {&lt;BR /&gt;	context.isRejected = true;&lt;BR /&gt;	context.rejectedMessages += "\n" + (String)globalMap.get("tDB2Output_1_ERROR_MESSAGE");	&lt;BR /&gt;}&lt;/PRE&gt; 
&lt;BR /&gt;I'm currently desperate. 
&lt;BR /&gt;That job is called by another one. 
&lt;BR /&gt;I see a stack trace of the exception in the console output. 
&lt;BR /&gt;My parent job passes its whole context (works : otherwise the job could not connect to the DB's). 
&lt;BR /&gt; 
&lt;BR /&gt;==&amp;gt; is this a bug? 
&lt;BR /&gt;Thank you for any quick (constructive) answer 
&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009MACn.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/154443iC5B8CACEF3D12C6A/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009MACn.png" alt="0683p000009MACn.png" /&gt;&lt;/span&gt; 
&lt;BR /&gt;Cheers,</description>
    <pubDate>Sat, 16 Nov 2024 13:39:25 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-11-16T13:39:25Z</dc:date>
    <item>
      <title>Catch Java Exceptions</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Catch-Java-Exceptions/m-p/2372193#M135056</link>
      <description>Hello all, 
&lt;BR /&gt;I desperately try to get a Java (SQL) Exception to be caught by Talend. 
&lt;BR /&gt;I read many posts which say "easy, just put a tLogCatcher". Of course, that won't work... 
&lt;BR /&gt;I tried about anything, without luck (and this should be soooo trivial). 
&lt;BR /&gt;(see picture) 
&lt;BR /&gt;I want to catch any exception/tDie... 
&lt;BR /&gt;This leads to a tJavaRow which uses a message I build with a tMap to put it in a context variable (context.rejectedMessages; String) and sets another context variable to specify it failed. 
&lt;BR /&gt; 
&lt;PRE&gt;context.isRejected = true;&lt;BR /&gt;context.rejectedMessages += input_row.message;&lt;/PRE&gt; 
&lt;BR /&gt;I tried with a 
&lt;BR /&gt; - tLogCatcher : catches all it can (Java Exception, tDie, tWarn); When I debug, the message in TalendException.printStackTrace() is not there when the component is looped for its messages (???) 
&lt;BR /&gt;(from the generated code) 
&lt;BR /&gt; 
&lt;PRE&gt;	private class TalendException extends Exception {&lt;BR /&gt;		private java.util.Map&amp;lt;String, Object&amp;gt; globalMap = null;&lt;BR /&gt;		private Exception e = null;&lt;BR /&gt;		private String currentComponent = null;&lt;BR /&gt;		private TalendException(Exception e, String errorComponent,&lt;BR /&gt;				final java.util.Map&amp;lt;String, Object&amp;gt; globalMap) {&lt;BR /&gt;			this.currentComponent = errorComponent;&lt;BR /&gt;			this.globalMap = globalMap;&lt;BR /&gt;			this.e = e;&lt;BR /&gt;		}&lt;BR /&gt;		@Override&lt;BR /&gt;		public void printStackTrace() {&lt;BR /&gt;			if (!(e instanceof TalendException || e instanceof TDieException)) {&lt;BR /&gt;				globalMap.put(currentComponent + "_ERROR_MESSAGE", e&lt;BR /&gt;						.getMessage());&lt;BR /&gt;				System.err&lt;BR /&gt;						.println("Exception in component " + currentComponent);&lt;BR /&gt;			}&lt;BR /&gt;			if (!(e instanceof TDieException)) {&lt;BR /&gt;				if (e instanceof TalendException) {&lt;BR /&gt;					e.printStackTrace();&lt;BR /&gt;				} else {&lt;BR /&gt;					e.printStackTrace();&lt;BR /&gt;					e.printStackTrace(errorMessagePS);&lt;BR /&gt;				}&lt;BR /&gt;			}&lt;BR /&gt;			if (!(e instanceof TalendException)) {&lt;BR /&gt;				try {&lt;BR /&gt;					for (java.lang.reflect.Method m : this.getClass()&lt;BR /&gt;							.getEnclosingClass().getMethods()) {&lt;BR /&gt;						if (m.getName().compareTo(currentComponent + "_error") == 0) {&lt;BR /&gt;							m.invoke(TX_SPAccoContractSupplements2TOST90.this,&lt;BR /&gt;									new Object[] { e, currentComponent,&lt;BR /&gt;											globalMap });&lt;BR /&gt;							break;&lt;BR /&gt;						}&lt;BR /&gt;					}&lt;BR /&gt;					if (!(e instanceof TDieException)) {&lt;BR /&gt;						tLogCatcher_1.addMessage("Java Exception",&lt;BR /&gt;								currentComponent, 6, e.getClass().getName()&lt;BR /&gt;										+ ":" + e.getMessage(), 1);&lt;BR /&gt;						tLogCatcher_1Process(globalMap);&lt;BR /&gt;					}&lt;BR /&gt;				} catch (java.lang.SecurityException e) {&lt;BR /&gt;					this.e.printStackTrace();&lt;BR /&gt;				} catch (java.lang.IllegalArgumentException e) {&lt;BR /&gt;					this.e.printStackTrace();&lt;BR /&gt;				} catch (java.lang.IllegalAccessException e) {&lt;BR /&gt;					this.e.printStackTrace();&lt;BR /&gt;				} catch (java.lang.reflect.InvocationTargetException e) {&lt;BR /&gt;					this.e.printStackTrace();&lt;BR /&gt;				} catch (TalendException e) {&lt;BR /&gt;					// do nothing&lt;BR /&gt;				}&lt;BR /&gt;			}&lt;BR /&gt;		}&lt;BR /&gt;	}&lt;/PRE&gt; 
&lt;BR /&gt;It enters the first "if" and prints out the exception trace; then it enters the "if (!(e instanceof TalendException)) " , finds the "_error" method and runs it; 
&lt;BR /&gt;then in "if (!(e instanceof TDieException))" it adds the java exception ("tLogCatcher_1.addMessage(....)"). Pretty cool, huh. 
&lt;BR /&gt;But at the next line ("tLogCatcher_1Process(globalMap);"), no message is found in this method's loop ==&amp;gt; nothing gets fired :'( 
&lt;BR /&gt; - a PostJob tJava which checks for globalMap.get("xxxx_ERROR_MESSAGE") without any luck : 
&lt;BR /&gt; 
&lt;PRE&gt;//check for errors... once again it is hardcoded...&lt;BR /&gt;if (globalMap.get("tPrejob_1_ERROR_MESSAGE") != null) {&lt;BR /&gt;	context.isRejected = true;&lt;BR /&gt;	context.rejectedMessages += "\n" + (String)globalMap.get("tPrejob_1_ERROR_MESSAGE");		&lt;BR /&gt;}&lt;BR /&gt;if (globalMap.get("tMSSqlConnection_1_ERROR_MESSAGE") != null) {&lt;BR /&gt;	context.isRejected = true;&lt;BR /&gt;	context.rejectedMessages += "\n" + (String)globalMap.get("tMSSqlConnection_1_ERROR_MESSAGE");		&lt;BR /&gt;}&lt;BR /&gt;if (globalMap.get("tDB2Connection_1_ERROR_MESSAGE") != null) {&lt;BR /&gt;	context.isRejected = true;&lt;BR /&gt;	context.rejectedMessages += "\n" + (String)globalMap.get("tDB2Connection_1_ERROR_MESSAGE");		&lt;BR /&gt;}&lt;BR /&gt;if (globalMap.get("tMSSqlInput_1_ERROR_MESSAGE") != null) {&lt;BR /&gt;	context.isRejected = true;&lt;BR /&gt;	context.rejectedMessages += "\n" + (String)globalMap.get("tMSSqlInput_1_ERROR_MESSAGE");		&lt;BR /&gt;}&lt;BR /&gt;if (globalMap.get("tDB2Output_1_ERROR_MESSAGE") != null) {&lt;BR /&gt;	context.isRejected = true;&lt;BR /&gt;	context.rejectedMessages += "\n" + (String)globalMap.get("tDB2Output_1_ERROR_MESSAGE");	&lt;BR /&gt;}&lt;/PRE&gt; 
&lt;BR /&gt;I'm currently desperate. 
&lt;BR /&gt;That job is called by another one. 
&lt;BR /&gt;I see a stack trace of the exception in the console output. 
&lt;BR /&gt;My parent job passes its whole context (works : otherwise the job could not connect to the DB's). 
&lt;BR /&gt; 
&lt;BR /&gt;==&amp;gt; is this a bug? 
&lt;BR /&gt;Thank you for any quick (constructive) answer 
&lt;span class="lia-inline-image-display-wrapper" image-alt="0683p000009MACn.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/154443iC5B8CACEF3D12C6A/image-size/large?v=v2&amp;amp;px=999" role="button" title="0683p000009MACn.png" alt="0683p000009MACn.png" /&gt;&lt;/span&gt; 
&lt;BR /&gt;Cheers,</description>
      <pubDate>Sat, 16 Nov 2024 13:39:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Catch-Java-Exceptions/m-p/2372193#M135056</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-16T13:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: Catch Java Exceptions</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Catch-Java-Exceptions/m-p/2372194#M135057</link>
      <description>Learning a bit more about the "problem". 
&lt;BR /&gt;When I debug, I check the tLogCatcher_1.getMessages() to see if my message is filled. Appearently, this does remove the messages that are read (correct me if I'm wrong) 
&lt;BR /&gt;==&amp;gt; when the loop uses getMessages, there is nothing anymore... 
&lt;BR /&gt;OK 
&lt;BR /&gt;==&amp;gt; my problem is the one that context variables need to be passed to the parent job via a tBufferOutput 
&lt;BR /&gt; 
&lt;A href="https://community.qlik.com/s/feed/0D53p00007vCpoiCAC" rel="nofollow noopener noreferrer"&gt;https://community.talend.com/t5/Design-and-Development/resolved-Passing-Context-Variable-from-Child-Job-to-Parent-Job/td-p/104620&lt;/A&gt; 
&lt;BR /&gt; I'll add the workaround to my 25 jobs my main big job which runs them all (and it's not quickly done in Studio, I can tell you). 
&lt;BR /&gt;Feature to add: 
&lt;BR /&gt;- enable IN/OUT for context variables. 
&lt;BR /&gt;- a better documentation/FAQ/........... the info is so unfindable. 
&lt;BR /&gt;Cheers, 
&lt;BR /&gt; 
&lt;BR /&gt;PS : sorry for the bad mood, but I am losing so much time in such things since I use Talend that it drives me insane</description>
      <pubDate>Mon, 07 Dec 2009 14:29:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Catch-Java-Exceptions/m-p/2372194#M135057</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-12-07T14:29:55Z</dc:date>
    </item>
  </channel>
</rss>

