Does using OnComponentError prevent an error from being thrown?

Six Stars

Does using OnComponentError prevent an error from being thrown?

In my main job, I have OnComponentError routed to tDie components in a few places. I also have a joblet set up to listen to Java Exceptions via the tLogCatcher. The joblet handles emailing, logging, and also has a tDie component at the end of it so the job completely ends on exception. My question is, if I have OnComponentError coming off a particular component, and that component fails, will it still throw an Exception for my joblet to catch or will it go to the tDie component and not hit my joblet.

 

My desired behavior is for all exceptions/errors to trigger the joblet so that errors get logged and emails triggered. I'm wondering if I need to avoid using "OnComponentError" flows altogether then or not.


Accepted Solutions
Seven Stars JGM
Seven Stars

Re: Does using OnComponentError prevent an error from being thrown?

if you take a peek at the generated java you can see that onComponentError links create try/catch blocks that will trap errors in the component. Unless you re-throw the exception after the onComponentError link, the tLogCatcher component will not see the errors

All Replies
Seven Stars JGM
Seven Stars

Re: Does using OnComponentError prevent an error from being thrown?

if you take a peek at the generated java you can see that onComponentError links create try/catch blocks that will trap errors in the component. Unless you re-throw the exception after the onComponentError link, the tLogCatcher component will not see the errors
Six Stars

Re: Does using OnComponentError prevent an error from being thrown?

That's super helpful, thank you!!

 

If I wanted to re-throw the error, which component would I use to do that?

Seven Stars JGM
Seven Stars

Re: Does using OnComponentError prevent an error from being thrown?

a tJava component with something like this in it should do it for you. You'll need to double check the globalMap key's your components or jobs populate to make sure you get the right error messages. 

 

throw new RuntimeException(((String)globalMap.get("<component_id>_ERROR_MESSAGE")));

 

depending on how your job is connected, you may need to wrap the throw statement in an "if" to prevent the unreachable code compile error:

 

if( true ) { 

    //throw exceptions

}

 

What’s New for Talend Spring ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Agile Data lakes & Analytics

Accelerate your data lake projects with an agile approach

Watch