Package net.ME1312.Galaxi.Library
Class Try
java.lang.Object
net.ME1312.Galaxi.Library.Try
Exception Handler Class
Remember that use of this class should always make your code shorter — it is not a replacement for native try-catch blocks
Remember that use of this class should always make your code shorter — it is not a replacement for native try-catch blocks
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
BiConsumer that could throw an exceptionstatic interface
BiFunction that could throw an exceptionstatic interface
Consumer that could throw an exceptionstatic interface
Function that could throw an exceptionstatic interface
Runnable that could throw an exceptionstatic interface
Supplier that could throw an exception -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Try
Handle specific exceptions<T> T
get
(Try.Supplier<T> value) Get a value despite exceptions<T> T
get
(Try.Supplier<T> value, Consumer<Throwable> err, T def) Get a value despite exceptions<T> T
get
(Try.Supplier<T> value, T def) Get a value despite exceptions<T> T
getOrConsume
(Try.Supplier<T> value, Consumer<Throwable> err) Get a value despite exceptions<T> T
getOrFunction
(Try.Supplier<T> value, Consumer<Throwable> err, Supplier<? extends T> def) Get a value despite exceptions<T> T
getOrFunction
(Try.Supplier<T> value, Function<Throwable, ? extends T> def) Get a value despite exceptions<T> T
getOrSupply
(Try.Supplier<T> value, Supplier<? extends T> def) Get a value despite exceptionsboolean
run
(Try.Runnable code) Run some codeboolean
run
(Try.Runnable code, Consumer<Throwable> err) Run some code
-
Field Details
-
all
Handle all exceptions -
none
Handle no exceptions
-
-
Method Details
-
expect
Handle specific exceptions- Parameters:
exceptions
- Exception types to handle- Returns:
- Exception Handler
-
run
Run some code- Parameters:
code
- Code to run- Returns:
- true if the code was run successfully (without exceptions)
-
run
Run some code- Parameters:
code
- Code to runerr
- Code to run for handling exceptions- Returns:
- true if the code was run successfully (without exceptions)
-
get
Get a value despite exceptions- Parameters:
value
- Code to run- Returns:
- The return value of that code (or null in the event of an exception)
-
get
Get a value despite exceptions- Parameters:
value
- Code to rundef
- Default value- Returns:
- The return value of that code (or def in the event of an exception)
-
get
Get a value despite exceptions- Parameters:
value
- Code to runerr
- Code to run for handling exceptionsdef
- Default value- Returns:
- The return value of that code (or def in the event of an exception)
-
getOrConsume
Get a value despite exceptions- Parameters:
value
- Code to runerr
- Code to run for handling exceptions- Returns:
- The return value of that code (or null in the event of an exception)
-
getOrSupply
Get a value despite exceptions- Parameters:
value
- Code to rundef
- Code to run for generating the default value in the event of an exception- Returns:
- The return value of either code block
-
getOrFunction
Get a value despite exceptions- Parameters:
value
- Code to rundef
- Code to run for handling exceptions and/or generating the default value in the event of an exception- Returns:
- The return value of either code block
-
getOrFunction
public <T> T getOrFunction(Try.Supplier<T> value, Consumer<Throwable> err, Supplier<? extends T> def) Get a value despite exceptions- Parameters:
value
- Code to runerr
- Code to run for handling exceptionsdef
- Code to run for generating the default value in the event of an exception- Returns:
- The return value of either code block
-