Skip to main content Skip to complementary content
Close announcements banner

Handling logs and exceptions

Before you begin

About this task

When building Artifacts, you can use specific components to collect exception data and transfer it to Talend Studio or to the web application.

When building Jobs, use:

  • tJobFailure to throw exception and stop the Artifact or Task execution
  • tLogCatcher to collect exception data and transfer it to Talend Studio or to the web application
  • tJobLog to define log information when executing Jobs in Talend Studio or Tasks in the web application

The example below shows how to collect data exceptions in a Job.

Procedure

  1. Build a Job to call a web service.

    Example

    Screenshot of a Job that calls a web service.
  2. Open the Basic settings view of the tJobFailure component.
  3. Enter Execution failed as the error type in the Error Type field.

    You can define the error type according to your needs and the value you define in this field will show in the run detail page when you run a Task in the web application.

  4. Enter the Java expression for the message in the Error Message field.

    Example

    "Error during call service: " + row6.faultString + " details:" + (row6.faultDetail != null ? row6.faultDetail.toString() : null)

    This means an exception will be thrown in case fault comes as response from the SOAP service. You can define the error message according to your needs.

  5. Build a subJob using tLogCatcher, tJobLog (x2) and tJobFailure.

    If you have imported the demo project, you can drop a ready-to-use exception handling subJob from the Joblets node in the Repository tree view. For further information about the demo project, see Importing demo projects.

  6. In the basic settings of the tLogCatcher component, select the Catch Java Exception and Catch tJobFailure options.

    The tLogCatcher component collects exception data and transfer it to Talend Studio or to the web application.

  7. In the basic settings of the first tJobLog component, select the Developer option and define the log message as the following in the Log message field:
    "\n | Action: " + row1.job + "\n | Component: " + row1.origin + "\n | Error type: " + row1.type + "\n | Error code: " + row1.code + "\n | Error message: " + row1.message

    This logs the error messages to Talend Studio.

  8. In the basic settings of the second tJobLog component, select the User option and define the log message as the following in the Log message field:
    row2.message

    This logs the error messages to the web application.

  9. In the basic settings of the tJobFailure component, set Execution failed as the error type and set the Java expression for the message in the Error Message field as the following, for example:
    row3.job + ":" + row3.origin +": " + row3.message

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!