public interface StaticThrowable<T extends StaticThrowable<T>>
Throwable
is intended to be
created once and reused. Throwables
that implement this interface
kept their state in a RealtimeThread
local data structure instead of
the object itself. This means that data is only valid until the next
StaticThrowable
is thrown in the context of the current thread.
Instances AsyncBaseEventHandler
always have some instance of
RealtimeThread
when executing. Having a marker interface makes it
easier to provide checking tools to ensure the proper throw sequence for all
Throwables
thrown from application code.
Throwables which implement this interface should define a get()
method that returns the singleton throwable of that class. It should also
initialize the stack backtrace. The message and cause should be cleared.
An application which throws a static exception should use the following paradigm:
throw LateStartException.get().init(<message>, <cause>);
The message must be initialized before the cause, because initMessage is
defined on StaticThrowable
but not Throwable
. Setting the
message and the cause are both optional.
Applications which define static throwables should extend one of
StaticError
, StaticCheckedException
, or
StaticRuntimeException
ConfigurationParameters
Modifier and Type | Interface and Description |
---|---|
static interface |
StaticThrowable.Hidden
A marker for static throwable support methods that should not be seen
in a stack trace.
|
Modifier and Type | Method and Description |
---|---|
Throwable |
fillInStackTrace()
Calls into the virtual machine to capture the current stack trace
in task's local memory.
|
Throwable |
getCause()
getCause returns the cause of this exception or
null when no cause
was set. |
String |
getLocalizedMessage()
Subclasses may override this message to get an error message that is
localized to the default locale.
|
String |
getMessage()
get the message describing the problem from task's local memory.
|
StaticThrowable<?> |
getSingleton()
For the case of legacy code that creates an RTSJ exception
explicity, this provides a means of obtaining its singleton version.
|
StackTraceElement[] |
getStackTrace()
Get the stack trace created by fillInStackTrace for this Throwable as an
array of StackTraceElements.
|
default T |
init()
Initialize the content of
StaticThrowableStorage with
neither a message nor a cause. |
default T |
init(String message)
Initialize the content of
StaticThrowableStorage with
just a message. |
default T |
init(String message,
Throwable cause)
Initialize the content of
StaticThrowableStorage with
a message and a cause. |
default T |
init(Throwable cause)
Initialize the content of
StaticThrowableStorage with
just a cause. |
Throwable |
initCause(Throwable causingThrowable)
Initializes the cause to the given Throwable is task's local memory.
|
void |
printStackTrace()
Print stack trace of this Throwable to System.err.
|
void |
printStackTrace(PrintStream stream)
Print the stack trace of this Throwable to the given stream.
|
void |
printStackTrace(PrintWriter s)
Print the stack trace of this Throwable to the given PrintWriter.
|
void |
setStackTrace(StackTraceElement[] new_stackTrace)
This method allows overriding the stack trace that was filled during
construction of this object.
|
default Object |
writeReplace()
Replace this objected with a special transport object when
serializing.
|
default T init(String message, Throwable cause)
StaticThrowableStorage
with
a message and a cause.message
- is the text to save.cause
- another Throwable
that led to this one.default T init(String message)
StaticThrowableStorage
with
just a message.message
- is the text to save.default T init(Throwable cause)
StaticThrowableStorage
with
just a cause.cause
- another Throwable
that led to this one.default T init()
StaticThrowableStorage
with
neither a message nor a cause.default Object writeReplace()
StaticThrowable<?> getSingleton()
String getMessage()
null
when no
message was set.String getLocalizedMessage()
By default it returns getMessage()
.
getMessage()
.Throwable initCause(Throwable causingThrowable)
StaticIllegalArgumentException
- when the cause is this Throwable
itself.causingThrowable
- the reason why this Throwable gets Thrown.Throwable getCause()
null
when no cause
was set. The cause is another exception that was caught before this
exception was created.null
.Throwable fillInStackTrace()
Throwable
.void setStackTrace(StackTraceElement[] new_stackTrace) throws NullPointerException
NullPointerException
- when new_stackTrace or any element of
new_stackTrace is null
.new_stackTrace
- the stack trace to replace be used.StackTraceElement[] getStackTrace()
The stack trace does not need to contain entries for all methods that are actually on the call stack, the virtual machine may decide to skip some stack trace entries. Even an empty array is a valid result of this function.
Repeated calls of this function without intervening calls to fillInStackTrace will return the same result.
When memory areas of the RTSJ are used (see MemoryArea
), and this
Throwable was allocated in a different memory area than the current
allocation context, the resulting stack trace will be allocated in either
the same memory area this was allocated in or the current memory area,
depending on which is the least deeply nested, thereby creating objects
that are assignment compatible with both areas.
null
.void printStackTrace()
The printed stack trace contains the result of toString() as the first line followed by one line for each stack trace element that contains the name of the method or constructor, optionally followed by the source file name and source file line number when available.
void printStackTrace(PrintStream stream)
The printed stack trace contains the result of toString() as the first line followed by one line for each stack trace element that contains the name of the method or constructor, optionally followed by the source file name and source file line number when available.
stream
- the stream to print to.void printStackTrace(PrintWriter s)
The printed stack trace contains the result of toString() as the first line followed by one line for each stack trace element that contains the name of the method or constructor, optionally followed by the source file name and source file line number when available.
s
- the PrintWriter to write to.aicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2019 aicas GmbH. All Rights Reserved.