- All Superinterfaces:
Broadcaster
,Listener
,Mixin
,NamedObject
,Receiver
,Repeater
,RepeaterMixin
,Transceiver
,Transmitter
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Removes exception handling from code that can throw a checked (or unchecked)
Exception
.
Methods are provided that provide exception handling. For example the code below executes the doIt() method and logs a warning and returns the default value false if the code throws an exception. This design allows the code to handle the checked exception in a succinct and readable way.
boolean doIt() throws NumberFormatException { [...] } [...] return UncheckedCode.of(this::doIt).or(false, "Unable to do it");
- Author:
- jonathanl (shibo)
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> UncheckedCode<T>
of
(UncheckedCode<T> code) default Value
default Value
default Value
default Value
default Value
orNull()
run()
Methods inherited from interface com.telenav.kivakit.core.messaging.Broadcaster
addListener, onTransmit, onTransmitted, onTransmitting, silence, transmit, transmitAll
Methods inherited from interface com.telenav.kivakit.core.messaging.Listener
isDeaf, listenTo, listenTo
Methods inherited from interface com.telenav.kivakit.interfaces.naming.NamedObject
hasSyntheticName, objectName, objectName
Methods inherited from interface com.telenav.kivakit.core.messaging.Repeater
isRepeating, onReceive
Methods inherited from interface com.telenav.kivakit.core.messaging.repeaters.RepeaterMixin
addListener, clearListeners, copyListeners, debugCodeContext, debugCodeContext, hasListeners, isReceiving, isTransmitting, listeners, messageSource, messageSource, onMessage, receive, removeListener, repeater, transmit
Methods inherited from interface com.telenav.kivakit.core.messaging.Transceiver
announce, debug, debugClassContext, fatal, fatal, glitch, glitch, glitch, glitch, halted, halted, ifDebug, illegalArgument, illegalState, illegalState, information, isDebugOn, narrate, problem, problem, problem, problem, problemIfNull, quibble, quibble, quibble, quibble, trace, trace, trace, trace, warning, warning, warning, warning
Methods inherited from interface com.telenav.kivakit.interfaces.messaging.Transmitter
withoutTransmitting
-
Method Details
-
orDefault
- Parameters:
defaultValue
- A default value to return if the code throws an exceptionmessage
- A warning message to give to the listener if an exception is thrownarguments
- Arguments to interpolate into the message- Returns:
- The value returned by the code, or the given default value if an exception is thrown
-
orDefault
- Returns:
- The value returned by the code, or a default value if an exception is thrown
-
orNull
-
run
- Returns:
- The value returned by the checked code
- Throws:
Exception
- The exception that might be thrown by the code