wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Java Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Exception" Watch "Java Exception" New topic
Author

Java Exception

Misbha Ali
Greenhorn

Joined: Jul 22, 2003
Posts: 7
I came across this code...I would appreciate if any one could make me understand this..specailly the new Object[] {rootCause} thing..
public DataServiceRiskWiseCheckedException(Code code, String debugInformation, Throwable rootCause, int severity)
{
this(code, new Object[] {rootCause}, debugInformation, rootCause, severity);
}
:roll:
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

It's a constructor for a user-defined class with a long name; looks like an Exception class. A subclass of Exception is just like any other class; it can have various member variables, and they can be initialized in the constructor. All that's going on here is that some user-defined Exception subclass has a whole lot of member variables, and they all get initialized in the constructor, and that's all we can see. This constructor calls another constructor using "this()" by slightly adapting the arguments -- particularly, turning a Throwable argument into an Object[] argument.
The phrase new Object[] { rootCause } constructs a one-element-long array of Object; the element is initialized to point to the object pointed to by "rootCause".


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Exception
 
Similar Threads
testing exceptions using JUnit
Is there a way in Java to Throw an exception and return an object too
compareTo() method
How to avoid persisting a child object, which is already there in database?
Color in JTable