001/* 002 * Copyright (C) 2009 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.google.common.testing; 018 019import com.google.common.annotations.GwtCompatible; 020import java.util.logging.Level; 021import java.util.logging.Logger; 022 023/** 024 * Simple utility for when you want to create a {@link TearDown} that may throw an exception but 025 * should not fail a test when it does. (The behavior of a {@code TearDown} that throws an exception 026 * varies; see its documentation for details.) Use it just like a {@code TearDown}, except override 027 * {@link #sloppyTearDown()} instead. 028 * 029 * @author Luiz-Otavio Zorzella 030 * @since 10.0 031 */ 032@GwtCompatible 033@ElementTypesAreNonnullByDefault 034public abstract class SloppyTearDown implements TearDown { 035 private static final Logger logger = Logger.getLogger(SloppyTearDown.class.getName()); 036 037 @Override 038 public final void tearDown() { 039 try { 040 sloppyTearDown(); 041 } catch (Throwable t) { 042 logger.log(Level.INFO, "exception thrown during tearDown: " + t.getMessage(), t); 043 } 044 } 045 046 public abstract void sloppyTearDown() throws Exception; 047}