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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Explore Salesforce OAuth Authorization Flows and Its Use Cases
  • Build a Flow Collectibles Portal Using Cadence (Part 2)
  • Build a Digital Collectibles Portal Using Flow and Cadence (Part 1)
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)

Trending

  • SaaS in an Enterprise - An Implementation Roadmap
  • Intro to RAG: Foundations of Retrieval Augmented Generation, Part 2
  • Caching 101: Theory, Algorithms, Tools, and Best Practices
  • Modern Test Automation With AI (LLM) and Playwright MCP

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.3K 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

  • Explore Salesforce OAuth Authorization Flows and Its Use Cases
  • Build a Flow Collectibles Portal Using Cadence (Part 2)
  • Build a Digital Collectibles Portal Using Flow and Cadence (Part 1)
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!