# Handling logs and exceptions

Available in...

* Cloud API Services Platform
* Cloud Big Data
* Cloud Big Data Platform
* Cloud Data Fabric
* Cloud Data Integration
* Cloud Data Management Platform
* Data Fabric
* Qlik Talend Cloud Enterprise Edition
* Qlik Talend Cloud Premium Edition

## Before you begin

* The Log4j option is enabled in the project settings. For further information, see [Activating and configuring Log4j](https://help.qlik.com/talend/en-US/studio-user-guide/8.0/studio-configure-log4j).

## 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.](https://help.qlik.com/talend/en-US/studio-user-guide/Resources/images/cloud-action-handle_exception2.png)
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](https://help.qlik.com/talend/en-US/studio-user-guide/8.0/importing-demo-project).
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