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

  • Home
  • SEARCH
  • 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 8626069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:56:08+00:00 2026-06-12T07:56:08+00:00

Can I create a Exception like A a = new A (new B (

  • 0

Can I create a Exception like

A a = new A (new B ( new A ) );

where A and B are two different type of Exception.

I know Java can do it but is it right to do that ?

Edit : I am writing an retry on type of Exception so I am checking the getCause of the Exception. I am breaking when getCause is null or getCause equal itself , Should I also break when getCause equals any Exception seen so far

  • 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-12T07:56:09+00:00Added an answer on June 12, 2026 at 7:56 am

    AException a = new AException (new BException ( new AException ) );

    This is legal.


    You can also initialize the cause directly using the initCause(Throwable) method.

    If you try to make exception its own cause; e.g.

     AException a = new AException();
     a.initCause(a);
    

    you will get an IllegalArgumentException("Self-causation not permitted"). (Thanks to Joachim Sauer for pointing that out.)

    While, the JVM will not stop you creating an indirect cycle, it is a really bad idea nonetheless.

    • It is an abuse of the Throwable API. It makes no logical sense for an exceptional event to have caused itself, directly or indirectly.

    • There is likely be code out there that assumes that the “cause” chain of an exception doesn’t have any cycles. Such code is likely to fail in a nasty way if it ever encounters a pathological exception with a cause cycle.

    Note that current generation (Java 7) printStackTrace() detects and deals with a “cause” cycles, but earlier generations did not:

    • http://srl.cs.berkeley.edu/~mhn/ftp/java/lang/Throwable.java.html
    • http://javasourcecode.org/html/open-source/jdk/jdk-6u23/java.lang/Throwable.java.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I create a new Exception different from the pre-made types? public class
I can create database manually by going to cpanel. But I'd like to create
I can create a contact that is not mail enabled, but how do I
I have an interesting problem. I'd like to create a generic class that can
I can create and use dynamic two dimensional array in Fortran (in 77 standard).
One can create an anonymous object that is initialized through constructor parameters, such as
How can create a New user in ORACLE with full access (alter, delete, select,
I can create an array of buttons in Windows Form but how can i
I am designing a control that can have two main states. The state will
Passing two parameters to a new thread on the threadpool can sometimes be complicated,

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.