File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Exception" Watch "Java Exception" New topic

Java Exception

Misbha Ali

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);
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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:
subject: Java Exception
It's not a secret anymore!