@Deprecated
public class TryBlockTemplate<Result>
extends java.lang.Object
try...catch...block 代码块模板类
try...catch...block code template class
// 选择性地覆盖方法,以便在不同的代码块中运行
public String lines() {
return new TryBlockTemplate<String>() {
//@Override
protected String doInTry(Object... args) {
return null;
}
//@Override
protected String doInCatch(Throwable t, Object... args) {
return null;
}
//@Override
protected void doInFinally(Object... args) {
}
}.tryWith();
}
Email: fishinlove@163.com
created by 2019/04/25 15:09:39
| 构造器和说明 |
|---|
TryBlockTemplate()
已过时。
|
| 限定符和类型 | 方法和说明 |
|---|---|
protected Result |
doInCatch(java.lang.Throwable t,
java.lang.Object... args)
已过时。
在 catch 块中执行
Do in catch block
|
protected void |
doInFinally(java.lang.Object... args)
已过时。
在 finally 块中执行
Do in finally block
|
protected Result |
doInTry(java.lang.Object... args)
已过时。
在 try 块中执行
Do in try block
|
Result |
tryWith(java.lang.Object... args)
已过时。
这是一个模板方法
包含了一个 try 代码块内容,由于这个代码块很常见,
所以创建一个模板类减少重复代码,并且将精力集中在业务上
子类可以选择性地复写其中的方法
This is a template about try block
Try block is so common, so I wanna to make it gracefully
Subclass should override some methods of it
try {
return doInTry(args);
} catch (Throwable t) {
return doInCatch(t, args);
} finally {
doInFinally(args);
}
|
public final Result tryWith(java.lang.Object... args)
这是一个模板方法
包含了一个 try 代码块内容,由于这个代码块很常见, 所以创建一个模板类减少重复代码,并且将精力集中在业务上
子类可以选择性地复写其中的方法
This is a template about try block
Try block is so common, so I wanna to make it gracefully
Subclass should override some methods of it
try {
return doInTry(args);
} catch (Throwable t) {
return doInCatch(t, args);
} finally {
doInFinally(args);
}
args - 可变参数,如果你需要使用到额外的参数,就通过这个参数传进来
Extendable parameters, if you wanna to use some parameters , then use it!
返回执行结果
Return result
protected Result doInTry(java.lang.Object... args) throws java.lang.Throwable
在 try 块中执行
Do in try block
args - 可变参数,如果你需要使用到额外的参数,就通过这个参数传进来
Extendable parameters, if you wanna to use some parameters , then use it!
返回执行结果
Return result
java.lang.Throwable - 执行抛出异常
The exception you throw
protected Result doInCatch(java.lang.Throwable t, java.lang.Object... args)
在 catch 块中执行
Do in catch block
t - 抛出的异常
The threw exception
args - 可变参数,如果你需要使用到额外的参数,就通过这个参数传进来
Extendable parameters, if you wanna to use some parameters , then use it!
返回执行结果
Return result
protected void doInFinally(java.lang.Object... args)
在 finally 块中执行
Do in finally block
args - 可变参数,如果你需要使用到额外的参数,就通过这个参数传进来
Extendable parameters, if you wanna to use some parameters , then use it!
Copyright © 2019. All Rights Reserved.