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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
Partner Zones AWS Cloud
by AWS Developer Relations
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
Partner Zones
AWS Cloud
by AWS Developer Relations

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.

Mansi Shanbhag user avatar by
Mansi Shanbhag
·
Sep. 18, 18 · Tutorial
Like (7)
Save
Tweet
Share
54.77K 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.

Popular on DZone

  • Cloud Performance Engineering
  • The Path From APIs to Containers
  • Spring Boot vs Eclipse MicroProfile: Resident Set Size (RSS) and Time to First Request (TFR) Comparative
  • gRPC on the Client Side

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: