Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2017 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 android.autofillservice.cts;
     18 
     19 import androidx.annotation.Nullable;
     20 
     21 /**
     22  * Exception that cause the {@link RetryRule} to re-try a test.
     23  */
     24 public class RetryableException extends RuntimeException {
     25 
     26     @Nullable
     27     private final Timeout mTimeout;
     28 
     29     public RetryableException(String msg) {
     30         this((Timeout) null, msg);
     31     }
     32 
     33     public RetryableException(String format, Object...args) {
     34         this((Timeout) null, String.format(format, args));
     35     }
     36 
     37     public RetryableException(Throwable cause, String format, Object...args) {
     38         this((Timeout) null, cause, String.format(format, args), cause);
     39     }
     40 
     41     public RetryableException(@Nullable Timeout timeout, String msg) {
     42         super(msg);
     43         this.mTimeout = timeout;
     44     }
     45 
     46     public RetryableException(@Nullable Timeout timeout, String format, Object...args) {
     47         super(String.format(format, args));
     48         this.mTimeout = timeout;
     49     }
     50 
     51     public RetryableException(@Nullable Timeout timeout, Throwable cause, String format,
     52             Object...args) {
     53         super(String.format(format, args), cause);
     54         this.mTimeout = timeout;
     55     }
     56 
     57     @Nullable
     58     public Timeout getTimeout() {
     59         return mTimeout;
     60     }
     61 
     62     @Override
     63     public String getMessage() {
     64         final String superMessage = super.getMessage();
     65         return mTimeout == null ? superMessage : superMessage + " (timeout=" + mTimeout + ")";
     66     }
     67 }
     68