• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding more information to Exception  RSS feed

 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exception class has a constructor like Exception(String message,Throwable cause).

but I want something like MyOwnException(String detail1,String Detail2,String Detail3,Throwable/Exception cause).

I have extended the Exception class and created such constructor. but I have to call super right? and I am stuck.

How one can add more information to exception?

Please advise.

PS :- I want to keep original stacktrace whilst adding more detail.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on JSP. For more information, please read this.

This post has been moved to a more appropriate forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
initCause() in java.lang.Throwable
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, you can add more information to your Exception subclass. But then you would have to add more methods for your subclass to return that information. Have a look at SQLException for an example of a class which does exactly that; note for example that there's a constructor which accepts something called SQLState, and also a method which returns the SQLState.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:initCause() in java.lang.Throwable

That's a good workaround if the super constructor does not take a cause.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!