Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8696465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:16:36+00:00 2026-06-13T01:16:36+00:00

I have some questions regarding handling exceptions in Java. I read a bit about

  • 0

I have some questions regarding handling exceptions in Java. I read a bit about it and got some contradicting guidelines.

Best Practices for Exception Handling

Let’s go through the mentioned article:

It states that one should generally avoid using checked exceptions if “Client code cannot do anything”. But what does it exactly mean? Is displaying error message in GUI sufficient reason for bubbling up checked exception? But it would force GUI programmer to remember to catch RuntimeExceptions and their descendants to display potential error info.

Second view presented in this article is that one should evade inventing own exception classes unless I want to implement some customs field/methods in them.
I generally disagree with this, my practice up today was just the opposite: I wrapped exceptions in my own exception structure to reflex goals realized by classes I write, even if they just extend Exception without adding any new methods. I think it helps to handle them more flexibly in the higher layers when thrown plus it’s generally more clear and comprehensible for programmer who will use these classes.

I implemented some code today ‘new way’ presented in the article throwing RuntimeException here and there, then I let Sonar analyze it. To confuse me even more Sonar marked my RuntimeExceptions as Major errors with a message like “Avoid throwing root type exceptions, wrap’em in your own types”.

So it looks quite controversional, what do you think?

I also heard from one of tech-leads today that just wrapping exceptions is bad, ‘because it’s a really costly operation for JVM’. For me, on the other side throwing SQLExceptions or IOExceptions everywhere looks like a bit of breaking encapsulation..

So what is your general attitude to questions I presented here?

  1. When to wrap exceptions in my own types, when I shouldn’t do this?

  2. Where is that point of ‘client cannot do anything about this, throw
    runtime exception?
    ‘

  3. What about performance issues?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:16:37+00:00Added an answer on June 13, 2026 at 1:16 am

    It looks like your tech-lead, as often, has escaped his role of developer because he wasn’t good at it.

    My advices would be:

    • prefer runtime exceptions over checked exceptions, especially if you’re not the only client of your API. Using a checked exception forces every client to handle the exception, even if it can’t do anything about it. If this is really what you want to do (i.e. forcing the caller to handle it), then a checked exception is what you want.
    • if the only thing the client can do when an exception happens is displaying a more or less generic error message such as “oops, something bad happened, please retry or go back to the welcome page”, then definitely use runtime exceptions. Most of the presentation frameworks provide a way to use a generic error handler.
    • definitely use exceptions that are linked to your abstraction layer. Throwing a SQLException from a high-level service is not adequate. Use existing exception types when they’re appropriate (like IllegalArgumentException to signal an illegal argument). Otherwise, wrap the low-level exception into a higher-level, appropriate exception type. What is costly is to throw an exception. Whether it wraps another one or not doesn’t matter much. And it should only happen exceptionally anyway.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read some documentation on how Adaboost works but have some questions regarding it.
I have some questions regarding java finalization. For example I have one class FileHelper
I have some questions regarding VB.NET bit shifting. I understand the << >> operators
I have some questions regarding the following css that I found: html, body {
There have been some similar questions asked regarding Grid views, but none have been
I have couple questions regarding some C++ rules. Why am I able to call
I have some question over here regarding the java garbage collector. First let me
I have some questions about importing data from Excel/CSV File into SQL Server. Let
I have some questions regarding the disposable classes. Suppose I have an IDisposable implementing
I have some questions regarding data base design for simple CMS. Every Page in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.