1 // Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 
6 package org.rocksdb;
7 
8 /**
9  * A RocksDBException encapsulates the error of an operation.  This exception
10  * type is used to describe an internal error from the c++ rocksdb library.
11  */
12 public class RocksDBException extends Exception {
13 
14   /* @Nullable */ private final Status status;
15 
16   /**
17    * The private construct used by a set of public static factory method.
18    *
19    * @param msg the specified error message.
20    */
RocksDBException(final String msg)21   public RocksDBException(final String msg) {
22     this(msg, null);
23   }
24 
RocksDBException(final String msg, final Status status)25   public RocksDBException(final String msg, final Status status) {
26     super(msg);
27     this.status = status;
28   }
29 
RocksDBException(final Status status)30   public RocksDBException(final Status status) {
31     super(status.getState() != null ? status.getState()
32         : status.getCodeString());
33     this.status = status;
34   }
35 
36   /**
37    * Get the status returned from RocksDB
38    *
39    * @return The status reported by RocksDB, or null if no status is available
40    */
getStatus()41   public Status getStatus() {
42     return status;
43   }
44 }
45