1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.statementservice; 18 19 import android.util.Log; 20 21 import java.util.concurrent.Callable; 22 import java.util.concurrent.ExecutionException; 23 import java.util.concurrent.FutureTask; 24 25 /** 26 * {@link FutureTask} that logs unhandled exceptions. 27 */ 28 final class ExceptionLoggingFutureTask<V> extends FutureTask<V> { 29 30 private final String mTag; 31 32 public ExceptionLoggingFutureTask(Callable<V> callable, String tag) { 33 super(callable); 34 mTag = tag; 35 } 36 37 @Override 38 protected void done() { 39 try { 40 get(); 41 } catch (ExecutionException | InterruptedException e) { 42 Log.e(mTag, "Uncaught exception.", e); 43 throw new RuntimeException(e); 44 } 45 } 46 } 47