All Products
Search
Document Center

ApsaraVideo Media Processing:Merge and edit videos

Last Updated:Feb 28, 2025

Video merging allows you to merge videos of different formats, bitrates, and resolutions into a longer video of a specific format, bitrate, and resolution. It is usually used to add opening or ending parts to a video, or to merge the clips of recorded live streams. Video clipping allows you to capture a clip from an original video, and save the clip as a new video. It is usually used to capture highlighted parts from videos. This topic describes how to merge and edit videos by using ApsaraVideo Media Processing (MPS) SDK for Java.

Scenarios

  • Intro video and a fixed outro video: Used to add a start or end part to a video, or to merge the clips of recorded live streams.

  • Clip splicing: Crop a specific clip of a video and output the clip as a new video file. This method is usually used to capture the highlights from videos.

  • Opening and ending: Special merging effects that allow you to embed opening and ending parts at the beginning and end of the input video. The opening parts are displayed in Picture-in-Picture (PiP) mode.

Merge multiple video clips in sequence

For example, an input video is captured from 00:00:03.000 and lasts for 00:00:00:13.000 seconds. The captured video is merged with the part from 00:00:01.000 to 00:00:05.030 of the opening. The total duration of the resulting video is 17.30 seconds.

/**
     * Merge multiple video clips in sequence.
     * @return
     * @throws Exception
     */
    public static void mergrUrlListJob() throws Exception {

        // Construct output parameters.
        JSONArray outputs = new JSONArray();

        // Configure the job input. Make sure that the media file used as the job input resides in the same region as the client.
        JSONObject input = new JSONObject();
        input.put("Bucket", "<your bucket name>");
        input.put("Location", "oss-cn-shanghai");

        // Configure the job output.
        JSONObject output = new JSONObject();
        try {
            input.put("Object", URLEncoder.encode("mps-test/demo/test.mp4", "utf-8"));
            String outPutObject = URLEncoder.encode("mps-test/demo/merge-out.mp4", "utf-8");
            output.put("OutputObject", outPutObject);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("input URL encode failed");
        }
        output.put("TemplateId", "<transcode templateId>");

        // Construct data for video clipping.
        JSONObject clip = new JSONObject();
        // Cut the video from 1.000s to 5.030s.
        clip.put("TimeSpan", "{\"Seek\":\"00:00:01.000\",\"Duration\":\"5.30\"}");
        // Cut the video from 1.000s to 5.030s that remains from the end of the video.
        //clip.put("TimeSpan", "{\"Seek\":\"00:00:01.000\",\"End\":\"5.30\"}");
        // Specifies whether to edit the first clip of the video. Valid values: true and false. A value of true specifies that the video clips are merged for a transcoding job after editing. A value of false specifies that the video clips are merged for a transcoding job before editing.
        clip.put("ConfigToClipFirstPart", true);

        // Construct data for video merging.
        JSONArray mergeList = new JSONArray();
        JSONObject merge = new JSONObject();
        merge.put("MergeURL", "http://bucket-name.oss-cn-shanghai.aliyuncs.com/" + URLEncoder.encode("mps-test/demo/test2mp4", "utf-8"));
        merge.put("Start", "00:00:03.000");
        merge.put("Duration", "00:00:13.000");

        mergeList.add(merge);
        output.put("Clip", clip);
        output.put("MergeList", mergeList);

        outputs.add(output);

        com.aliyun.mts20140618.Client client = MergeClipJobs.createClient();
        com.aliyun.mts20140618.models.SubmitJobsRequest submitJobsRequest = new com.aliyun.mts20140618.models.SubmitJobsRequest()
                // The job input.
                .setInput(input.toJSONString())
                // The job output configuration.
                .setOutputs(outputs.toJSONString())
                // The OSS bucket in which the output file is stored.
                .setOutputBucket("exampleBucket")
                // The region in which the OSS bucket resides.
                .setOutputLocation("oss-cn-shanghai")
                // The ID of the pipeline.
                .setPipelineId("dd3dae411e704030b921e52698e5****");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Write your own code to display the response of the API operation if necessary.
            client.submitJobsWithOptions(submitJobsRequest, runtime);
        } catch (TeaException error) {
            // Handle exceptions with caution in actual business scenarios and do not ignore the exceptions in your project. In this example, exceptions are provided for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Handle exceptions with caution in actual business scenarios and do not ignore the exceptions in your project. In this example, exceptions are provided for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }

Merge video clips by using the OSS path of a configuration file

For example, an input video is captured from 00:00:03.000 and lasts for 00:00:00:10.000 seconds. The captured video is merged with the part from 00:00:01.000 to 00:00:05.030 to the end of the opening.

Sample content of mergeConfigfile:

{"MergeList":[{"MergeURL":"https://bucket-name.oss-cn-beijing.aliyuncs.com/mps-test/demo/test2.mp4","Start":"00:00:03.000","Duration":"00:00:10.000"}]}

/**
     * Merge video clips by using the OSS path of a configuration file.
     * @return
     * @throws Exception
     */
    public static void mergrConfigFileJob() throws Exception {

        // Construct output parameters.
        JSONArray outputs = new JSONArray();

        // Configure the job input. Make sure that the media file used as the job input resides in the same region as the client.
        JSONObject input = new JSONObject();
        input.put("Bucket", "<your bucket name>");
        input.put("Location", "oss-cn-shanghai");

        // Configure the job output.
        JSONObject output = new JSONObject();
        try {
            input.put("Object", URLEncoder.encode("mps-test/demo/test.mp4", "utf-8"));
            String outPutObject = URLEncoder.encode("mps-test/demo/merge-out.mp4", "utf-8");
            output.put("OutputObject", outPutObject);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("input URL encode failed");
        }
        output.put("TemplateId", "<transcode templateId>");

        // Construct data for video clipping.
        JSONObject clip = new JSONObject();
        // Cut the video from 1.000s to 5.030s.
        clip.put("TimeSpan", "{\"Seek\":\"00:00:01.000\",\"Duration\":\"5.30\"}");
        // Cut the video from 1.000s to 5.030s that remains from the end of the video.
        //clip.put("TimeSpan", "{\"Seek\":\"00:00:01.000\",\"End\":\"5.30\"}");
        // Specifies whether to edit the first clip of the video. Valid values: true and false. A value of true specifies that the video clips are merged for a transcoding job after editing. A value of false specifies that the video clips are merged for a transcoding job before editing.
        clip.put("ConfigToClipFirstPart", true);

        output.put("Clip", clip);
        // The OSS path of the configuration file must be an HTTP URL.
        output.put("MergeConfigUrl", "http://bucket-name.oss-cn-shanghai.aliyuncs.com/mps-test/demo/mergeConfigfile");

        outputs.add(output);

        com.aliyun.mts20140618.Client client = MergeClipJobs.createClient();
        com.aliyun.mts20140618.models.SubmitJobsRequest submitJobsRequest = new com.aliyun.mts20140618.models.SubmitJobsRequest()
                // The job input.
                .setInput(input.toJSONString())
                // The job output configuration.
                .setOutputs(outputs.toJSONString())
                // The OSS bucket in which the output file is stored.
                .setOutputBucket("exampleBucket")
                // The region in which the OSS bucket resides.
                .setOutputLocation("oss-cn-shanghai")
                // The ID of the pipeline.
                .setPipelineId("dd3dae411e704030b921e52698e5****");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Write your own code to display the response of the API operation if necessary.
            client.submitJobsWithOptions(submitJobsRequest, runtime);
        } catch (TeaException error) {
            // Handle exceptions with caution in actual business scenarios and do not ignore the exceptions in your project. In this example, exceptions are provided for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Handle exceptions with caution in actual business scenarios and do not ignore the exceptions in your project. In this example, exceptions are provided for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }

Embed opening parts at the beginning of the input video or add ending parts to the end of the input video

For example, an open part with the resolution of 680 × 480 is added at the third second of the input video. In addition, an ending part with the resolution of 680 × 480 is added to the end of the input video. The blank part after the ending part is added is filled with white color background.

Note

Objects specified by URLs of the opening and ending parts must be UTF-8-encoded, and the URLs must be HTTP addresses. For more information, see URL encoding.

 /**
     * Embed opening parts at the beginning of the input video or add ending parts to the end of the input video.
     * @return
     * @throws Exception
     */
    public static void openAndTailJob() throws Exception {

        // Construct output parameters.
        JSONArray outputs = new JSONArray();

        // Configure the job input. Make sure that the media file used as the job input resides in the same region as the client.
        JSONObject input = new JSONObject();
        input.put("Bucket", "<your bucket name>");
        input.put("Location", "oss-cn-shanghai");

        // Configure the job output.
        JSONObject output = new JSONObject();
        try {
            input.put("Object", URLEncoder.encode("mps-test/demo/test.mp4", "utf-8"));
            String outPutObject = URLEncoder.encode("mps-test/demo/merge-out.mp4", "utf-8");
            output.put("OutputObject", outPutObject);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("input URL encode failed");
        }
        output.put("TemplateId", "<transcode templateId>");

        JSONArray openingList = new JSONArray();
        JSONObject opening = new JSONObject();
        opening.put("OpenUrl", "http://bucket-name.oss-cn-shanghai.aliyuncs.com/" + URLEncoder.encode("mps-test/demo/open.mp4", "utf-8"));
        opening.put("Start", "3");
        opening.put("Width", "680");
        opening.put("Height", "480");
        openingList.add(opening);

        JSONArray tailSlateList = new JSONArray();
        JSONObject tailSlate = new JSONObject();
        // Objects specified by URLs of the opening and ending parts must be UTF-8-encoded. 
        tailSlate.put("TailUrl", "http://bucket-name.oss-cn-shanghai.aliyuncs.com/" + URLEncoder.encode("mps-test/demo/tail.mp4", "utf-8"));
        tailSlate.put("BlendDuration", "2");
        tailSlate.put("Width", "680");
        tailSlate.put("Height", "480");
        tailSlate.put("IsMergeAudio", true);
        tailSlate.put("BgColor", "White");
        tailSlateList.add(tailSlate);

        output.put("OpeningList", openingList);
        output.put("TailSlateList", tailSlateList);
        outputs.add(output);

        com.aliyun.mts20140618.Client client = MergeClipJobs.createClient();
        com.aliyun.mts20140618.models.SubmitJobsRequest submitJobsRequest = new com.aliyun.mts20140618.models.SubmitJobsRequest()
                // The job input.
                .setInput(input.toJSONString())
                // The job output configuration.
                .setOutputs(outputs.toJSONString())
                // The OSS bucket in which the output file is stored.
                .setOutputBucket("exampleBucket")
                // The region in which the OSS bucket resides.
                .setOutputLocation("oss-cn-shanghai")
                // The ID of the pipeline.
                .setPipelineId("dd3dae411e704030b921e52698e5****");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Write your own code to display the response of the API operation if necessary.
            client.submitJobsWithOptions(submitJobsRequest, runtime);
        } catch (TeaException error) {
            // Handle exceptions with caution in actual business scenarios and do not ignore the exceptions in your project. In this example, exceptions are provided for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Handle exceptions with caution in actual business scenarios and do not ignore the exceptions in your project. In this example, exceptions are provided for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }

Complete sample code

package com.alibaba.bltest.api_v2;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.tea.TeaException;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class MergeClipJobs {

    /**
     * <b>description</b> :
     * <p>Use your AccessKey pair to initialize the client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.mts20140618.Client createClient() throws Exception {

        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "mts.cn-shanghai.aliyuncs.com";
        return new com.aliyun.mts20140618.Client(config);
    }

    /**
     * Merge multiple video clips in sequence.
     * @return
     * @throws Exception
     */
    public static void mergrUrlListJob() throws Exception {

        // Construct output parameters.
        JSONArray outputs = new JSONArray();

        // Configure the job input. Make sure that the media file used as the job input resides in the same region as the client.
        JSONObject input = new JSONObject();
        input.put("Bucket", "<your bucket name>");
        input.put("Location", "oss-cn-shanghai");

        // Configure the job output.
        JSONObject output = new JSONObject();
        try {
            input.put("Object", URLEncoder.encode("mps-test/demo/test.mp4", "utf-8"));
            String outPutObject = URLEncoder.encode("mps-test/demo/merge-out.mp4", "utf-8");
            output.put("OutputObject", outPutObject);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("input URL encode failed");
        }
        output.put("TemplateId", "<transcode templateId>");

        // Construct data for video clipping.
        JSONObject clip = new JSONObject();
        // Cut the video from 1.000s to 5.030s.
        clip.put("TimeSpan", "{\"Seek\":\"00:00:01.000\",\"Duration\":\"5.30\"}");
        // Cut the video from 1.000s to 5.030s that remains from the end of the video.
        //clip.put("TimeSpan", "{\"Seek\":\"00:00:01.000\",\"End\":\"5.30\"}");
        // Specifies whether to edit the first clip of the video. Valid values: true and false. A value of true specifies that the video clips are merged for a transcoding job after editing. A value of false specifies that the video clips are merged for a transcoding job before editing.
        clip.put("ConfigToClipFirstPart", true);

        // Construct data for video merging.
        JSONArray mergeList = new JSONArray();
        JSONObject merge = new JSONObject();
        merge.put("MergeURL", "http://bucket-name.oss-cn-shanghai.aliyuncs.com/" + URLEncoder.encode("mps-test/demo/test2mp4", "utf-8"));
        merge.put("Start", "00:00:03.000");
        merge.put("Duration", "00:00:13.000");

        mergeList.add(merge);
        output.put("Clip", clip);
        output.put("MergeList", mergeList);

        outputs.add(output);

        com.aliyun.mts20140618.Client client = MergeClipJobs.createClient();
        com.aliyun.mts20140618.models.SubmitJobsRequest submitJobsRequest = new com.aliyun.mts20140618.models.SubmitJobsRequest()
                // The job input.
                .setInput(input.toJSONString())
                // The job output configuration.
                .setOutputs(outputs.toJSONString())
                // The OSS bucket in which the output file is stored.
                .setOutputBucket("exampleBucket")
                // The region in which the OSS bucket resides.
                .setOutputLocation("oss-cn-shanghai")
                // The ID of the pipeline.
                .setPipelineId("dd3dae411e704030b921e52698e5****");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Write your own code to display the response of the API operation if necessary.
            client.submitJobsWithOptions(submitJobsRequest, runtime);
        } catch (TeaException error) {
            // Handle exceptions with caution in actual business scenarios and do not ignore the exceptions in your project. In this example, exceptions are provided for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Handle exceptions with caution in actual business scenarios and do not ignore the exceptions in your project. In this example, exceptions are provided for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }

    /**
     * Merge video clips by using the OSS path of a configuration file.
     * @return
     * @throws Exception
     */
    public static void mergrConfigFileJob() throws Exception {

        // Construct output parameters.
        JSONArray outputs = new JSONArray();

        // Configure the job input. Make sure that the media file used as the job input resides in the same region as the client.
        JSONObject input = new JSONObject();
        input.put("Bucket", "<your bucket name>");
        input.put("Location", "oss-cn-shanghai");

        // Configure the job output.
        JSONObject output = new JSONObject();
        try {
            input.put("Object", URLEncoder.encode("mps-test/demo/test.mp4", "utf-8"));
            String outPutObject = URLEncoder.encode("mps-test/demo/merge-out.mp4", "utf-8");
            output.put("OutputObject", outPutObject);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("input URL encode failed");
        }
        output.put("TemplateId", "<transcode templateId>");

        // Construct data for video clipping.
        JSONObject clip = new JSONObject();
        // Cut the video from 1.000s to 5.030s.
        clip.put("TimeSpan", "{\"Seek\":\"00:00:01.000\",\"Duration\":\"5.30\"}");
        // Cut the video from 1.000s to 5.030s that remains from the end of the video.
        //clip.put("TimeSpan", "{\"Seek\":\"00:00:01.000\",\"End\":\"5.30\"}");
        // Specifies whether to edit the first clip of the video. Valid values: true and false. A value of true specifies that the video clips are merged for a transcoding job after editing. A value of false specifies that the video clips are merged for a transcoding job before editing.
        clip.put("ConfigToClipFirstPart", true);

        output.put("Clip", clip);
        // The OSS path of the configuration file must be an HTTP URL.
        output.put("MergeConfigUrl", "http://bucket-name.oss-cn-shanghai.aliyuncs.com/mps-test/demo/mergeConfigfile");

        outputs.add(output);

        com.aliyun.mts20140618.Client client = MergeClipJobs.createClient();
        com.aliyun.mts20140618.models.SubmitJobsRequest submitJobsRequest = new com.aliyun.mts20140618.models.SubmitJobsRequest()
                // The job input.
                .setInput(input.toJSONString())
                // The job output configuration.
                .setOutputs(outputs.toJSONString())
                // The OSS bucket in which the output file is stored.
                .setOutputBucket("exampleBucket")
                // The region in which the OSS bucket resides.
                .setOutputLocation("oss-cn-shanghai")
                // The ID of the pipeline.
                .setPipelineId("dd3dae411e704030b921e52698e5****");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Write your own code to display the response of the API operation if necessary.
            client.submitJobsWithOptions(submitJobsRequest, runtime);
        } catch (TeaException error) {
            // Handle exceptions with caution in actual business scenarios and do not ignore the exceptions in your project. In this example, exceptions are provided for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Handle exceptions with caution in actual business scenarios and do not ignore the exceptions in your project. In this example, exceptions are provided for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }

    /**
     * Embed opening parts at the beginning of the input video or add ending parts to the end of the input video.
     * @return
     * @throws Exception
     */
    public static void openAndTailJob() throws Exception {

        // Construct output parameters.
        JSONArray outputs = new JSONArray();

        // Configure the job input. Make sure that the media file used as the job input resides in the same region as the client.
        JSONObject input = new JSONObject();
        input.put("Bucket", "<your bucket name>");
        input.put("Location", "oss-cn-shanghai");

        // Configure the job output.
        JSONObject output = new JSONObject();
        try {
            input.put("Object", URLEncoder.encode("mps-test/demo/test.mp4", "utf-8"));
            String outPutObject = URLEncoder.encode("mps-test/demo/merge-out.mp4", "utf-8");
            output.put("OutputObject", outPutObject);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("input URL encode failed");
        }
        output.put("TemplateId", "<transcode templateId>");

        JSONArray openingList = new JSONArray();
        JSONObject opening = new JSONObject();
        opening.put("OpenUrl", "http://bucket-name.oss-cn-shanghai.aliyuncs.com/" + URLEncoder.encode("mps-test/demo/open.mp4", "utf-8"));
        opening.put("Start", "3");
        opening.put("Width", "680");
        opening.put("Height", "480");
        openingList.add(opening);

        JSONArray tailSlateList = new JSONArray();
        JSONObject tailSlate = new JSONObject();
        // Objects specified by URLs of the opening and ending parts must be UTF-8-encoded. 
        tailSlate.put("TailUrl", "http://bucket-name.oss-cn-shanghai.aliyuncs.com/" + URLEncoder.encode("mps-test/demo/tail.mp4", "utf-8"));
        tailSlate.put("BlendDuration", "2");
        tailSlate.put("Width", "680");
        tailSlate.put("Height", "480");
        tailSlate.put("IsMergeAudio", true);
        tailSlate.put("BgColor", "White");
        tailSlateList.add(tailSlate);

        output.put("OpeningList", openingList);
        output.put("TailSlateList", tailSlateList);
        outputs.add(output);

        com.aliyun.mts20140618.Client client = MergeClipJobs.createClient();
        com.aliyun.mts20140618.models.SubmitJobsRequest submitJobsRequest = new com.aliyun.mts20140618.models.SubmitJobsRequest()
                // The job input.
                .setInput(input.toJSONString())
                // The job output configuration.
                .setOutputs(outputs.toJSONString())
                // The OSS bucket in which the output file is stored.
                .setOutputBucket("exampleBucket")
                // The region in which the OSS bucket resides.
                .setOutputLocation("oss-cn-shanghai")
                // The ID of the pipeline.
                .setPipelineId("dd3dae411e704030b921e52698e5****");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Write your own code to display the response of the API operation if necessary.
            client.submitJobsWithOptions(submitJobsRequest, runtime);
        } catch (TeaException error) {
            // Handle exceptions with caution in actual business scenarios and do not ignore the exceptions in your project. In this example, exceptions are provided for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // Handle exceptions with caution in actual business scenarios and do not ignore the exceptions in your project. In this example, exceptions are provided for reference only. 
            // The error message.
            System.out.println(error.getMessage());
            // The URL for troubleshooting.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

References