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
Nested ClassesModifier and TypeClassDescriptionstatic interfaceBiConsumer that could throw an exceptionstatic interfaceBiFunction that could throw an exceptionstatic interfaceConsumer that could throw an exceptionstatic interfaceFunction that could throw an exceptionstatic interfaceRunnable that could throw an exceptionstatic interfaceSupplier that could throw an exception -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TryHandle specific exceptions<T> Tget(Try.Supplier<T> value) Get a value despite exceptions<T> Tget(Try.Supplier<T> value, Consumer<Throwable> err, T def) Get a value despite exceptions<T> Tget(Try.Supplier<T> value, T def) Get a value despite exceptions<T> TgetOrConsume(Try.Supplier<T> value, Consumer<Throwable> err) Get a value despite exceptions<T> TgetOrFunction(Try.Supplier<T> value, Consumer<Throwable> err, Supplier<? extends T> def) Get a value despite exceptions<T> TgetOrFunction(Try.Supplier<T> value, Function<Throwable, ? extends T> def) Get a value despite exceptions<T> TgetOrSupply(Try.Supplier<T> value, Supplier<? extends T> def) Get a value despite exceptionsbooleanrun(Try.Runnable code) Run some codebooleanrun(Try.Runnable code, Consumer<Throwable> err) Run some code
-
Field Details
-
all
Handle all exceptions -
none
Handle no exceptions
-
-
Constructor Details
-
Try
Handle specific exceptions- Parameters:
suppressor- Exception suppressor
-
-
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
-