DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How Power Automate Helps Analysts Send Alert Emails Faster and How AI Builder Takes It to the Next Level
  • 2 Hidden Bottlenecks in Large-Scale Azure Migrations
  • How to Create a Custom React Component in Vaadin Flow
  • Explore Salesforce OAuth Authorization Flows and Its Use Cases

Trending

  • Architecting Petabyte-Scale Hyperspectral Pipelines on AWS
  • Throughput vs Goodput: The Performance Metric You Are Probably Ignoring in LLM Testing
  • RAG Done Right: When to Use SQL, Search, and Vector Retrieval and How To Combine Them
  • Detecting Bugs and Vulnerabilities in Java With SonarQube

Error Handling in Mule

The new Error Handling is one of the major changes introduced in Mule 4 and it's better and more efficient according to one person.

By 
Mansi Shanbhag user avatar
Mansi Shanbhag
·
Updated Sep. 18, 18 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
58.8K Views

Join the DZone community and get the full member experience.

Join For Free

The new Error Handling is one of the major changes introduced in Mule 4. It's better and more efficient. Although it may seem complex to some, it's made complex for good.

To begin with, the message exceptions can now be handled at 3 different levels i.e. application, flow, and processor levels, as shown below.

Image title

The handlers written at the application level are global handlers, which can be used to handle the errors thrown by any flow, which doesn't have its own error handling.

If there is no error handling written at any of the levels, the Mule Default Error Handler is used, which stops the execution of the flow and logs the exception.

The Mule Default Error Handler is not configurable but, can be replaced by our own Global error handler by creating a Configuration global element.

About Error Objects

Every error that is thrown, creates an Error object named as follows — Namespace (eg. HTTP) and Identifier (eg. BAD_REQUEST)

Eg. HTTP: BAD_REQUEST, WSC: CONNECTIVITY, VALIDATION: INVALID_BOOLEAN

Each error object has 2 properties:

  • error.errorType — an object holding the Namespace and identifier

  • error.description — a string holding the error message

All the errors follow a Hierarchy as shown below. “ANY” is the most Generic parent.

Image title

About Error Handler Scopes

There are two error handler scopes in Mule 4, i.e., On Error Continue and On Error Propagate, which can be used to handle different kind of errors at all three levels.

Image title

The ON ERROR CONTINUE scope always returns a success response to the next level, while the ON ERROR PROPAGATE always propagates the error to the next level and returns an error response to the next level.

Each scope can have one or more message processors.

About Global Handlers

To handle errors at the application level, add an error handler in the global.xml (or simply outside a flow).

Then, create a Configuration element in the global elements, which sets the Global Error Handler as the Default Error Handler.

Image title

Image title

To create a generic handler for handling all the errors, specify the TYPE as “ANY” in the error scope of the Global Handler. To handle multiple errors, different type, or errors separately, specify the errorType of the error in the Type box of the error scope.

Image title

The error will be handled by the first scope, which meets the errorType.

About Flow Level Handlers

Flow level handlers can be added to regular Flows and private flows, but not to Subflows.

If an error that is thrown in the flow, doesn’t find a matching scope for its errorType in the Flow’s error scopes, it DOES NOT go to the application level handler, instead, it uses the Mule Default Error Handler.

About Processor Level Handlers

To handle the errors at the processor level, add one or more processors into a Try Scope and handle it using the On Error Propagate or On Error Continue Scopes.

The error scopes at the processor level take precedence over flow-level scopes. Flow-level scopes take precedence over application-level scopes.

It would be a good idea to have an error scope with Type specified as ANY in each level to avoid getting unexpected errors propagated to next levels.

Finally, the most important and challenging part of the new error handling is to choose between On Error Propagate and On Error Continue Scopes. Select them according to the business requirement or logic. For eg.: If you want the child flow to return a success to parent flow so that the parent flow continues, use On Error Continue. Similarly, use On Error Propagate when you may want the error to be propagated from child flow to parent flow and return an error response.

Flow (web browser)

Opinions expressed by DZone contributors are their own.

Related

  • How Power Automate Helps Analysts Send Alert Emails Faster and How AI Builder Takes It to the Next Level
  • 2 Hidden Bottlenecks in Large-Scale Azure Migrations
  • How to Create a Custom React Component in Vaadin Flow
  • Explore Salesforce OAuth Authorization Flows and Its Use Cases

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook