本文整理了Java中java.lang.RuntimeException.addSuppressed()
方法的一些代码示例,展示了RuntimeException.addSuppressed()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RuntimeException.addSuppressed()
方法的具体详情如下:
包路径:java.lang.RuntimeException
类名称:RuntimeException
方法名:addSuppressed
暂无
代码示例来源:origin: apache/incubator-druid
private void runCallbacks()
{
RuntimeException e = null;
for (Runnable callback = shutdownCallbacks.poll(); callback != null; callback = shutdownCallbacks.poll()) {
try {
callback.run();
}
catch (RuntimeException ex) {
if (e == null) {
e = new RuntimeException("Error running callback");
}
e.addSuppressed(ex);
}
}
if (e != null) {
throw e;
}
}
代码示例来源:origin: neo4j/neo4j
/**
* If the given obj is AutoCloseable, then close it.
* Any exceptions thrown from the close method will be wrapped in RuntimeExceptions.
* These RuntimeExceptions can get the given suppressedException attached to them, if any.
* If the given suppressedException argument is null, then it will not be added to the
* thrown RuntimeException.
*/
static void closeSafely( Object obj, Throwable suppressedException )
{
if ( obj instanceof AutoCloseable )
{
AutoCloseable closeable = (AutoCloseable) obj;
try
{
closeable.close();
}
catch ( Exception cause )
{
RuntimeException exception = new RuntimeException( cause );
if ( suppressedException != null )
{
exception.addSuppressed( suppressedException );
}
throw exception;
}
}
}
}
代码示例来源:origin: neo4j/neo4j
/**
* If the given obj is AutoCloseable, then close it.
* Any exceptions thrown from the close method will be wrapped in RuntimeExceptions.
* These RuntimeExceptions can get the given suppressedException attached to them, if any.
* If the given suppressedException argument is null, then it will not be added to the
* thrown RuntimeException.
*/
static void closeSafely( Object obj, Throwable suppressedException )
{
if ( obj instanceof AutoCloseable )
{
AutoCloseable closeable = (AutoCloseable) obj;
try
{
closeable.close();
}
catch ( Exception cause )
{
RuntimeException exception = new RuntimeException( cause );
if ( suppressedException != null )
{
exception.addSuppressed( suppressedException );
}
throw exception;
}
}
}
}
代码示例来源:origin: reactor/reactor-core
/**
* Create a composite exception that wraps the given {@link Throwable Throwable(s)},
* as suppressed exceptions. Instances create by this method can be detected using the
* {@link #isMultiple(Throwable)} check. The {@link #unwrapMultiple(Throwable)} method
* will correctly unwrap these to a {@link List} of the suppressed exceptions. Note
* that is will also be consistent in producing a List for other types of exceptions
* by putting the input inside a single-element List.
*
* @param throwables the exceptions to wrap into a composite
* @return a composite exception with a standard message, and the given throwables as
* suppressed exceptions
* @see #addThrowable(AtomicReferenceFieldUpdater, Object, Throwable)
*/
public static RuntimeException multiple(Iterable<Throwable> throwables) {
RuntimeException multiple = new RuntimeException("Multiple exceptions");
//noinspection ConstantConditions
if (throwables != null) {
for (Throwable t : throwables) {
//this is ok, multiple is always a new non-singleton instance
multiple.addSuppressed(t);
}
}
return multiple;
}
代码示例来源:origin: apache/storm
@Override
public void close() {
if (closed) {
return;
}
RuntimeException saved = null;
for (Iterator<String> it = super.iterator(); it.hasNext();) {
String name = it.next();
try {
client.killTopologyWithOpts(name, NO_WAIT_KILL);
it.remove();
} catch (Exception e) {
RuntimeException wrapped = new RuntimeException("Error trying to kill " + name, e);
if (saved != null) {
saved.addSuppressed(wrapped);
} else {
saved = wrapped;
}
}
}
super.clear();
if (saved != null) {
throw saved;
}
closed = true;
}
}
代码示例来源:origin: embulk/embulk
public RuntimeException getRepresentativeException() {
RuntimeException top = null;
for (Throwable ex : getExceptions()) {
if (top != null) {
top.addSuppressed(ex);
} else {
if (ex instanceof RuntimeException) {
top = (RuntimeException) ex;
} else {
top = new RuntimeException(ex);
}
}
}
if (top == null) {
top = new RuntimeException("Some transactions are not committed");
}
return top;
}
代码示例来源:origin: konsoletyper/teavm
@Override
public void close() throws Exception {
RuntimeException previousException = null;
try {
closeHandler.run();
} catch (RuntimeException e) {
previousException = e;
}
try {
innerStream.close();
} catch (RuntimeException e) {
if (previousException != null) {
e.addSuppressed(previousException);
}
throw e;
}
}
}
代码示例来源:origin: konsoletyper/teavm
@Override
public void close() throws Exception {
RuntimeException previousException = null;
try {
closeHandler.run();
} catch (RuntimeException e) {
previousException = e;
}
try {
innerStream.close();
} catch (RuntimeException e) {
if (previousException != null) {
e.addSuppressed(previousException);
}
throw e;
}
}
}
代码示例来源:origin: konsoletyper/teavm
@Override
public void close() throws Exception {
RuntimeException previousException = null;
try {
closeHandler.run();
} catch (RuntimeException e) {
previousException = e;
}
try {
innerStream.close();
} catch (RuntimeException e) {
if (previousException != null) {
e.addSuppressed(previousException);
}
throw e;
}
}
}
代码示例来源:origin: konsoletyper/teavm
@Override
public void close() throws Exception {
RuntimeException previousException = null;
try {
closeHandler.run();
} catch (RuntimeException e) {
previousException = e;
}
try {
innerStream.close();
} catch (RuntimeException e) {
if (previousException != null) {
e.addSuppressed(previousException);
}
throw e;
}
}
}
代码示例来源:origin: com.h2database/h2
e.addSuppressed(e2);
throw e;
代码示例来源:origin: konsoletyper/teavm
@Override
public void close() throws Exception {
RuntimeException suppressed = null;
try {
first.close();
} catch (RuntimeException e) {
suppressed = e;
}
try {
second.close();
} catch (RuntimeException e) {
if (suppressed != null) {
e.addSuppressed(suppressed);
}
throw e;
}
}
}
代码示例来源:origin: konsoletyper/teavm
@Override
public void close() throws Exception {
RuntimeException suppressed = null;
try {
first.close();
} catch (RuntimeException e) {
suppressed = e;
}
try {
second.close();
} catch (RuntimeException e) {
if (suppressed != null) {
e.addSuppressed(suppressed);
}
throw e;
}
}
}
代码示例来源:origin: konsoletyper/teavm
@Override
public void close() throws Exception {
RuntimeException suppressed = null;
try {
first.close();
} catch (RuntimeException e) {
suppressed = e;
}
try {
second.close();
} catch (RuntimeException e) {
if (suppressed != null) {
e.addSuppressed(suppressed);
}
throw e;
}
}
}
代码示例来源:origin: konsoletyper/teavm
@Override
public void close() throws Exception {
RuntimeException suppressed = null;
try {
first.close();
} catch (RuntimeException e) {
suppressed = e;
}
try {
second.close();
} catch (RuntimeException e) {
if (suppressed != null) {
e.addSuppressed(suppressed);
}
throw e;
}
}
}
代码示例来源:origin: neo4j/neo4j
@Override
public void close()
{
RuntimeException exception = null;
for ( Pair<SnapshotDeletionPolicy,IndexCommit> policyAndCommit : snapshots )
{
try
{
policyAndCommit.first().release( policyAndCommit.other() );
}
catch ( IOException | RuntimeException e )
{
if ( exception == null )
{
exception = e instanceof IOException ?
new UncheckedIOException( (IOException) e ) :
(RuntimeException) e;
}
else
{
exception.addSuppressed( e );
}
}
}
if ( exception != null )
{
throw exception;
}
}
};
代码示例来源:origin: jenkinsci/jenkins
RuntimeException exception = new RuntimeException(message.toString(), iterator.next());
while (iterator.hasNext()) {
exception.addSuppressed(iterator.next());
代码示例来源:origin: apache/incubator-druid
public static void cleanup(Job job) throws IOException
{
final Path jobDir = getJobPath(job.getJobID(), job.getWorkingDirectory());
final FileSystem fs = jobDir.getFileSystem(job.getConfiguration());
RuntimeException e = null;
try {
JobHelper.deleteWithRetry(fs, jobDir, true);
}
catch (RuntimeException ex) {
e = ex;
}
try {
JobHelper.deleteWithRetry(fs, getJobClassPathDir(job.getJobName(), job.getWorkingDirectory()), true);
}
catch (RuntimeException ex) {
if (e == null) {
e = ex;
} else {
e.addSuppressed(ex);
}
}
if (e != null) {
throw e;
}
}
代码示例来源:origin: apache/ignite
/**
* @throws Exception If failed.
*/
@Test
public void testXGetSuppressedList() throws Exception {
IgniteCheckedException me = prepareMultiException();
assertEquals(3, X.getSuppressedList(me).size());
RuntimeException e = new RuntimeException();
e.addSuppressed(me);
List<Throwable> suppresseds = X.getSuppressedList(e);
assertEquals(4, suppresseds.size());
assertEquals("Test message.", suppresseds.get(0).getMessage());
for (int i = 1; i <= 3; i++)
assertEquals("Demo exception.", suppresseds.get(1).getMessage());
}
代码示例来源:origin: neo4j/neo4j
initException.addSuppressed( closeException );
内容来源于网络,如有侵权,请联系作者删除!