Skip to content

Commit 40c5124

Browse files
committed
Add rethrowing exception, from Apache Commons Lang.
1 parent 759afae commit 40c5124

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.schabi.newpipe.extractor.services.youtube.YoutubeThrottlingDecrypter;
3434
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
3535
import org.schabi.newpipe.extractor.stream.*;
36+
import org.schabi.newpipe.extractor.utils.ExceptionUtils;
3637
import org.schabi.newpipe.extractor.utils.JsonUtils;
3738
import org.schabi.newpipe.extractor.utils.Parser;
3839
import org.schabi.newpipe.extractor.utils.Utils;
@@ -799,8 +800,12 @@ public void onFetchPage(@Nonnull final Downloader downloader)
799800
nextFuture.get();
800801
fetchAndroidFuture.get();
801802
fetchDesktopSts.get();
802-
} catch (InterruptedException | ExecutionException e) {
803-
e.printStackTrace();
803+
} catch (InterruptedException ignored) {
804+
} catch (ExecutionException e) {
805+
final Throwable cause = e.getCause();
806+
if (cause != null) {
807+
ExceptionUtils.rethrow(cause);
808+
}
804809
}
805810
}
806811

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.schabi.newpipe.extractor.utils;
2+
3+
public class ExceptionUtils {
4+
5+
// From Apache Commons Lang: https://commons.apache.org/proper/commons-lang/javadocs/api-3.10/org/apache/commons/lang3/exception/ExceptionUtils.html#rethrow-java.lang.Throwable-
6+
7+
public static <R> R rethrow(final Throwable throwable) {
8+
// claim that the typeErasure invocation throws a RuntimeException
9+
return ExceptionUtils.<R, RuntimeException>typeErasure(throwable);
10+
}
11+
12+
@SuppressWarnings("unchecked")
13+
private static <R, T extends Throwable> R typeErasure(final Throwable throwable) throws T {
14+
throw (T) throwable;
15+
}
16+
}

0 commit comments

Comments
 (0)