com.google.android.exoplayer2.util.Util.sneakyThrow()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(1.8k)|赞(0)|评价(0)|浏览(172)

本文整理了Java中com.google.android.exoplayer2.util.Util.sneakyThrow()方法的一些代码示例,展示了Util.sneakyThrow()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.sneakyThrow()方法的具体详情如下:
包路径:com.google.android.exoplayer2.util.Util
类名称:Util
方法名:sneakyThrow

Util.sneakyThrow介绍

[英]A hacky method that always throws t even if t is a checked exception, and is not declared to be thrown.
[中]一种黑客方法,即使t是已检查的异常,也总是抛出t,并且未声明要抛出。

代码示例

代码示例来源:origin: google/ExoPlayer

@Override
public void close() throws IOException {
 closed = true;
 Throwable thrown = null;
 try {
  flush();
 } catch (Throwable e) {
  thrown = e;
 }
 try {
  out.close();
 } catch (Throwable e) {
  if (thrown == null) {
   thrown = e;
  }
 }
 if (thrown != null) {
  Util.sneakyThrow(thrown);
 }
}

代码示例来源:origin: google/ExoPlayer

/**
 * Runs the provided {@link Runnable} on the playback thread, blocking until execution completes.
 *
 * @param runnable The {@link Runnable} to run.
 */
public void runOnPlaybackThread(final Runnable runnable) {
 final Throwable[] throwable = new Throwable[1];
 final ConditionVariable finishedCondition = new ConditionVariable();
 playbackHandler.post(
   () -> {
    try {
     runnable.run();
    } catch (Throwable e) {
     throwable[0] = e;
    } finally {
     finishedCondition.open();
    }
   });
 assertThat(finishedCondition.block(TIMEOUT_MS)).isTrue();
 if (throwable[0] != null) {
  Util.sneakyThrow(throwable[0]);
 }
}

代码示例来源:origin: google/ExoPlayer

/**
 * Runs the provided {@link Runnable} on the playback thread, blocking until execution completes.
 *
 * @param runnable The {@link Runnable} to run.
 */
public void runOnPlaybackThread(final Runnable runnable) {
 final Throwable[] throwable = new Throwable[1];
 final ConditionVariable finishedCondition = new ConditionVariable();
 playbackHandler.post(
   () -> {
    try {
     runnable.run();
    } catch (Throwable e) {
     throwable[0] = e;
    } finally {
     finishedCondition.open();
    }
   });
 assertThat(finishedCondition.block(TIMEOUT_MS)).isTrue();
 if (throwable[0] != null) {
  Util.sneakyThrow(throwable[0]);
 }
}

相关文章