1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.mojo.system; 6 7 /** 8 * Exception for the core mojo API. 9 */ 10 public class MojoException extends RuntimeException { 11 12 private final int mCode; 13 14 /** 15 * Constructor. 16 */ MojoException(int code)17 public MojoException(int code) { 18 mCode = code; 19 } 20 21 /** 22 * Constructor. 23 */ MojoException(Throwable cause)24 public MojoException(Throwable cause) { 25 super(cause); 26 mCode = MojoResult.UNKNOWN; 27 } 28 29 /** 30 * The mojo result code associated with this exception. See {@link MojoResult} for possible 31 * values. 32 */ getMojoResult()33 public int getMojoResult() { 34 return mCode; 35 } 36 37 /** 38 * @see Object#toString() 39 */ 40 @Override toString()41 public String toString() { 42 return "MojoResult(" + mCode + "): " + MojoResult.describe(mCode); 43 } 44 } 45