forked from mongodb/mongo-java-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMongoException.java
More file actions
171 lines (142 loc) · 4.23 KB
/
Copy pathMongoException.java
File metadata and controls
171 lines (142 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// MongoException.java
/**
* Copyright (C) 2008 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mongodb;
import org.bson.BSONObject;
/**
* A general exception raised in Mongo
* @author antoine
*/
public class MongoException extends RuntimeException {
private static final long serialVersionUID = -4415279469780082174L;
/**
* @param msg the message
*/
public MongoException( String msg ){
super( msg );
_code = -3;
}
/**
*
* @param code the error code
* @param msg the message
*/
public MongoException( int code , String msg ){
super( msg );
_code = code;
}
/**
*
* @param msg the message
* @param t the throwable cause
*/
public MongoException( String msg , Throwable t ){
super( msg , _massage( t ) );
_code = -4;
}
/**
*
* @param code the error code
* @param msg the message
* @param t the throwable cause
*/
public MongoException( int code , String msg , Throwable t ){
super( msg , _massage( t ) );
_code = code;
}
/**
* Creates a MongoException from a BSON object representing an error
* @param o
*/
public MongoException( BSONObject o ){
this( ServerError.getCode( o ) , ServerError.getMsg( o , "UNKNOWN" ) );
}
static MongoException parse( BSONObject o ){
String s = ServerError.getMsg( o , null );
if ( s == null )
return null;
return new MongoException( ServerError.getCode( o ) , s );
}
static Throwable _massage( Throwable t ){
if ( t instanceof Network )
return ((Network)t)._ioe;
return t;
}
/**
* Subclass of MongoException representing a network-related exception
*/
public static class Network extends MongoException {
private static final long serialVersionUID = -4415279469780082174L;
Network( String msg , java.io.IOException ioe ){
super( -2 , msg , ioe );
_ioe = ioe;
}
Network( java.io.IOException ioe ){
super( ioe.toString() , ioe );
_ioe = ioe;
}
final java.io.IOException _ioe;
}
/**
* Subclass of MongoException representing a duplicate key exception
*/
public static class DuplicateKey extends MongoException {
private static final long serialVersionUID = -4415279469780082174L;
DuplicateKey( int code , String msg ){
super( code , msg );
}
}
/**
* Subclass of MongoException representing a cursor-not-found exception
*/
public static class CursorNotFound extends MongoException {
private static final long serialVersionUID = -4415279469780082174L;
private final long cursorId;
private final ServerAddress serverAddress;
/**
*
* @param cursorId
* @param serverAddress
*/
CursorNotFound(long cursorId, ServerAddress serverAddress){
super( -5 , "cursor " + cursorId + " not found on server " + serverAddress );
this.cursorId = cursorId;
this.serverAddress = serverAddress;
}
/**
* Get the cursor id that wasn't found.
* @return
*/
public long getCursorId() {
return cursorId;
}
/**
* The server address where the cursor is.
* @return
*/
public ServerAddress getServerAddress() {
return serverAddress;
}
}
/**
* Gets the exception code
* @return
*/
public int getCode(){
return _code;
}
final int _code;
}