This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception constructor for Java 1.7 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception constructor for Java 1.7" Watch "Exception constructor for Java 1.7" New topic
Author

Exception constructor for Java 1.7

Nick Widelec
Ranch Hand

Joined: Feb 28, 2013
Posts: 226

Hi,

Having seen the following from the official javadoc:


Exception

protected Exception(String message,
Throwable cause,
boolean enableSuppression,
boolean writableStackTrace)

Constructs a new exception with the specified detail message, cause, suppression enabled or disabled, and writable stack trace enabled or disabled.

Parameters:
message - the detail message.
cause - the cause. (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
enableSuppression - whether or not suppression is enabled or disabled
writableStackTrace - whether or not the stack trace should be writable
Since:
1.7


I noted that it's protected so only aimed to be overridden by custom exception in case. However what is a writableStackTrace?
As it's been added in Java 1.7 I would like to know that in order to avoid surprises at the exam.

Thanks.


@ Saloon keepers: Could you please remove the status of resolved to this topic "Question about OCPJP HAS-A reletionship" present in this forum? Thanks.


OCAJP 7, OCPJP 7
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

See Throwable


protected Throwable(String message,
Throwable cause,
boolean enableSuppression,
boolean writableStackTrace)
Constructs a new throwable with the specified detail message, cause, suppression enabled or disabled, and writable stack trace enabled or disabled. If suppression is disabled, getSuppressed() for this object will return a zero-length array and calls to addSuppressed(java.lang.Throwable) that would otherwise append an exception to the suppressed list will have no effect. If the writable stack trace is false, this constructor will not call fillInStackTrace(), a null will be written to the stackTrace field, and subsequent calls to fillInStackTrace and setStackTrace(StackTraceElement[]) will not set the stack trace. If the writable stack trace is false, getStackTrace() will return a zero length array.
Note that the other constructors of Throwable treat suppression as being enabled and the stack trace as being writable. Subclasses of Throwable should document any conditions under which suppression is disabled and document conditions under which the stack trace is not writable. Disabling of suppression should only occur in exceptional circumstances where special requirements exist, such as a virtual machine reusing exception objects under low-memory situations. Circumstances where a given exception object is repeatedly caught and rethrown, such as to implement control flow between two sub-systems, is another situation where immutable throwable objects would be appropriate.

Parameters:
message - the detail message.
cause - the cause. (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
enableSuppression - whether or not suppression is enabled or disabled
writableStackTrace - whether or not the stack trace should be writable
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception constructor for Java 1.7