By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
World of SoftwareWorld of SoftwareWorld of Software
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Search
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
Reading: Refactoring 035 – Use Separate Exception Hierarchies for Business and Technical Errors | HackerNoon
Share
Sign In
Notification Show More
Font ResizerAa
World of SoftwareWorld of Software
Font ResizerAa
  • Software
  • Mobile
  • Computing
  • Gadget
  • Gaming
  • Videos
Search
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Have an existing account? Sign In
Follow US
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
World of Software > Computing > Refactoring 035 – Use Separate Exception Hierarchies for Business and Technical Errors | HackerNoon
Computing

Refactoring 035 – Use Separate Exception Hierarchies for Business and Technical Errors | HackerNoon

News Room
Last updated: 2025/10/13 at 5:46 PM
News Room Published 13 October 2025
Share
SHARE

Distinguish your technical failures from business rules

TL;DR: Use separate exception hierarchies for business and technical errors.

Problems Addressed 😔

  • Confused contracts
  • Mixed responsibilities and error treatment
  • Difficult handling
  • Poor readability
  • Misleading signals
  • Exceptions for expected cases
  • Nested Exceptions
  • Mixed exception hierarchies
  • Improper error responses
  • Tangled architectural concerns
  • Mixed alarms

Related Code Smells 💨

https://maximilianocontieri.com/code-smell-72-return-codes?embedable=true

https://maximilianocontieri.com/code-smell-73-exceptions-for-expected-cases?embedable=true

https://maximilianocontieri.com/code-smell-80-nested-trycatch?embedable=true

https://www.linkedin.com/pulse/code-smell-184-exception-arrow-maximiliano-contieri?embedable=true

https://www.linkedin.com/pulse/code-smell-132-exception-try-too-broad-maximiliano-contieri?embedable=true

Steps 👣

  1. Identify business exceptions
  2. Identify technical exceptions
  3. Create two separate exception hierarchies
  4. Update the code to throw the right one
  5. Adjust handlers accordingly

Sample Code 💻

Before 🚨

public void Withdraw(int amount) {
  if (amount > Balance) {
    throw new Exception("Insufficient funds");
    // You might want to show this error to end users
  }
  if (connection == null) {
    throw new Exception("Database not available");
    // Internal error, log and notify operators. 
    // Fail with a more generic error
  }
  Balance -= amount;
}

After 👉

// 1. Identify business exceptions
public class BusinessException : Exception {}
public class InsufficientFunds : BusinessException {}

// 2. Identify technical exceptions
public class TechnicalException : Exception {}
public class DatabaseUnavailable : TechnicalException {}

public void Withdraw(int amount) {
  // 3. Use the correct hierarchy
  if (amount > Balance) {
    throw new InsufficientFunds();
  }
  if (connection == null) {
    throw new DatabaseUnavailable();
  }

  // 4. Apply safe logic
  Balance -= amount;
}

// 5. Adjust handlers in the calling code

Type 📝

[X] Manual

Safety 🛡️

This refactoring is safe if you apply it gradually and update your code with care.

You must ensure all thrown exceptions are caught at the proper architectural level.

Why is the Code Better? ✨

You make the code clearer and more predictable.

You express technical failures and business rules separately, taking corrective actions with different stakeholders.

You also reduce confusion for the caller and improve maintainability.

How Does it Improve the Bijection? 🗺️

This refactoring strengthens the mapping between real-world concepts and code representation.

In reality, business rule violations and technical failures are fundamentally different situations.

Business exceptions represent expected alternative flows in your domain model.

Technical exceptions represent unexpected system problems that break the execution environment.

By separating these concerns, your code more accurately reflects the real-world distinction between “business says no” and “system cannot proceed”.

Limitations ⚠️

You need discipline to maintain two hierarchies.

If you misuse them, the benefits are lost. You also need to communicate the contract clearly to the clients of your code.

You should also create your own integrity tests to enforce these rules.

Refactor with AI 🤖

Suggested Prompt: 1. Identify business exceptions 2. Identify technical exceptions 3. Create two separate hierarchies 4. Update code to throw the right one 5. Adjust handlers accordingly

Without Proper Instructions 📵

  • ChatGPT
  • Claude
  • Perplexity
  • Copilot
  • You
  • Gemini
  • DeepSeek
  • Meta AI
  • Grok
  • Qwen

With Specific Instructions 👩‍🏫

  • ChatGPT
  • Claude
  • Perplexity
  • Copilot
  • You
  • Gemini
  • DeepSeek
  • Meta AI
  • Grok
  • Qwen

Tags 🏷️

  • Exceptions

Level 🔋

[X] Intermediate

Related Refactorings 🔄

https://www.linkedin.com/pulse/refactoring-004-remove-unhandled-exceptions-maximiliano-contieri-ebhzf?embedable=true

Credits 🙏

Image by Ottó on Pixabay


This article is part of the Refactoring Series.

https://www.linkedin.com/pulse/how-improve-your-code-easy-refactorings-maximiliano-contieri?embedable=true

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Email Print
Share
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Mental Models in Architecture and Societal Views of Technology: A Conversation with Nimisha Asthagiri
Next Article Google Meet adds a new trick for when you’re not camera-ready
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow

Latest News

The HackerNoon Newsletter: Can ChatGPT Outperform the Market? Week 9 (10/13/2025) | HackerNoon
Computing
Google's Nano Banana Brings More Visual Flair to NotebookLM's Video Overviews
News
Google will allow you to hide ads in your search results, but only after scrolling
News
Jack Ma praises Alibaba’s changes in the past year under new chairman and CEO · TechNode
Computing

You Might also Like

Computing

The HackerNoon Newsletter: Can ChatGPT Outperform the Market? Week 9 (10/13/2025) | HackerNoon

2 Min Read
Computing

Jack Ma praises Alibaba’s changes in the past year under new chairman and CEO · TechNode

1 Min Read
Computing

ViaBTC Unveils Enhanced Collateralized Loan Service for Global Miners | HackerNoon

2 Min Read
Computing

Blizzard Chinese server restores data, takes new reservations · TechNode

1 Min Read
//

World of Software is your one-stop website for the latest tech news and updates, follow us now to get the news that matters to you.

Quick Link

  • Privacy Policy
  • Terms of use
  • Advertise
  • Contact

Topics

  • Computing
  • Software
  • Press Release
  • Trending

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

World of SoftwareWorld of Software
Follow US
Copyright © All Rights Reserved. World of Software.
Welcome Back!

Sign in to your account

Lost your password?