wood burning stoves*
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 Android Security Essentials Live Lessons this week in the Android 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: 24183
    
  34

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]
 
Don't get me started about those stupid light bulbs.
 
subject: Java Exception
 
Similar Threads
Color in JTable
Is there a way in Java to Throw an exception and return an object too
testing exceptions using JUnit
How to avoid persisting a child object, which is already there in database?
compareTo() method