Forums Register Login

Exception constructor for Java 1.7

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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

 
Is that a spider in your hair? Here, threaten it with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1006 times.
Similar Threads
try-with-resources from Java tutorial
java.io.IOException: Premature EOF
URLyBird : DB Interface & Exceptions: Please HELP!
Use threads to "stop" the execution of a method without a "return"?
Periodic errors when launching from Web Start
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:15:31.