mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
异常处理
This commit is contained in:
parent
3b327ec7c3
commit
e2303e24dd
@ -108,9 +108,17 @@ public class KClassUtil {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T newInstance(final Class<T> targetType, final ValueProvider<String> valueProvider) {
|
||||
final List<?> constructors = getConstructors(targetType);
|
||||
RuntimeException exception = null;
|
||||
for (final Object constructor : constructors) {
|
||||
final Object[] parameterValues = getParameterValues(constructor, valueProvider);
|
||||
return (T) KCallable.call(constructor, parameterValues);
|
||||
try {
|
||||
return (T) KCallable.call(constructor, parameterValues);
|
||||
} catch (RuntimeException e) {
|
||||
exception = e;
|
||||
}
|
||||
}
|
||||
if (exception != null) {
|
||||
throw exception;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user