Skip to content

safe call method function,and don't worry about exception throwing errors

License

Notifications You must be signed in to change notification settings

KubrickLiu/safe-call

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apache License, Version 2.0, January 2004 Maven Central

safe-call

safe call method function,and don't worry about exception throwing errors

What this is

This is a set of security wrapper classes. The error of the wrapped function will not affect the caller, and the underlying throwable can be consumed separately;

  • 这是一套安全包装 Wrap 类,被 wrap 的函数报错不会影响到调用者,底层的 throwable 可以被单独消费

Quick-start

Maven:

<dependency>
    <groupId>io.github.kubrickliu</groupId>
    <artifactId>safe-call</artifactId>
    <version>1.0.1</version>
</dependency>

Example Code :

1. SafeCall (include the return value)

1.1. simple use :

SafeCall.wrap(() -> {
    // do real method function
});

1.2. use with default value :

SafeCall.wrap(() -> {
    // do real method function
}, {default_value}); // The second value is the default value in case of exception

1.3. use with default value and consumer throwable :

SafeCall.wrap(() -> {
    // do real method function
}, {default_value}, throwable -> {
    // consumer throwable
});

2. SafeExec (exclude the return value)

2.1. simple use :

SafeExec.wrap(() -> {
    // do real method function
});

2.2. use and consumer throwable

SafeExec.wrap(() -> {
    // do real method function
}, throwable -> {
    // consumer throwable
});

About

safe call method function,and don't worry about exception throwing errors

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages