1 package android.hardware.camera2.utils; 2 3 import android.hardware.camera2.CameraAccessException; 4 5 /** 6 * @hide 7 */ 8 public class CameraRuntimeException extends RuntimeException { 9 10 private final int mReason; 11 private String mMessage; 12 private Throwable mCause; 13 getReason()14 public final int getReason() { 15 return mReason; 16 } 17 CameraRuntimeException(int problem)18 public CameraRuntimeException(int problem) { 19 super(); 20 mReason = problem; 21 } 22 CameraRuntimeException(int problem, String message)23 public CameraRuntimeException(int problem, String message) { 24 super(message); 25 mReason = problem; 26 mMessage = message; 27 } 28 CameraRuntimeException(int problem, String message, Throwable cause)29 public CameraRuntimeException(int problem, String message, Throwable cause) { 30 super(message, cause); 31 mReason = problem; 32 mMessage = message; 33 mCause = cause; 34 } 35 CameraRuntimeException(int problem, Throwable cause)36 public CameraRuntimeException(int problem, Throwable cause) { 37 super(cause); 38 mReason = problem; 39 mCause = cause; 40 } 41 42 /** 43 * Recreate this exception as the CameraAccessException equivalent. 44 * @return CameraAccessException 45 */ asChecked()46 public CameraAccessException asChecked() { 47 CameraAccessException e; 48 49 if (mMessage != null && mCause != null) { 50 e = new CameraAccessException(mReason, mMessage, mCause); 51 } else if (mMessage != null) { 52 e = new CameraAccessException(mReason, mMessage); 53 } else if (mCause != null) { 54 e = new CameraAccessException(mReason, mCause); 55 } else { 56 e = new CameraAccessException(mReason); 57 } 58 // throw and catch, so java has a chance to fill out the stack trace 59 e.setStackTrace(this.getStackTrace()); 60 61 return e; 62 } 63 } 64