Skip to content

Commit def48df

Browse files
author
Hugo Bonacci
committed
Adding new exception messages
1 parent bd1a156 commit def48df

7 files changed

+161
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace CSMongo.Exceptions {
7+
8+
/// <summary>
9+
/// Thrown when a request is sent to the server but
10+
/// the connection has not been opened yet
11+
/// </summary>
12+
public class ConnectionNotOpenedException : InvalidOperationException {
13+
14+
/// <summary>
15+
/// Throws an exception that the connection isn't ready yet
16+
/// </summary>
17+
public ConnectionNotOpenedException(string host)
18+
: base(string.Format("Connection to {0} has not been opened yet. Either use 'autoconnect' or Open() before sending requests.", host)) {
19+
}
20+
21+
}
22+
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace CSMongo.Exceptions {
7+
8+
/// <summary>
9+
/// Thrown when a connection string cannot be parsed
10+
/// </summary>
11+
public class InvalidMongoConnectionStringException : ArgumentException {
12+
13+
/// <summary>
14+
/// Throws that the provided connection stirng is not
15+
/// in an acceptable format
16+
/// </summary>
17+
public InvalidMongoConnectionStringException()
18+
: base("The connection string provided was not in the correct format.") {
19+
}
20+
21+
}
22+
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace CSMongo.Exceptions {
7+
8+
/// <summary>
9+
/// Thrown when an empty string is used as a MongoCollection name
10+
/// </summary>
11+
public class MissingCollectionNameException : ArgumentException {
12+
13+
/// <summary>
14+
/// Throws that a collection name was not found
15+
/// </summary>
16+
public MissingCollectionNameException(string argument)
17+
: base("You must provide the name for the MongoCollection to access", argument) {
18+
}
19+
20+
}
21+
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace CSMongo.Exceptions {
7+
8+
/// <summary>
9+
/// Thrown when a type cannot be deserialized into an expected type
10+
/// </summary>
11+
public class MongoDeserializationException : ApplicationException {
12+
13+
/// <summary>
14+
/// Throws that deserialization failed for the type requested
15+
/// </summary>
16+
public MongoDeserializationException(Exception ex)
17+
: base("Couldn't deserialize into the requested type.", ex) {
18+
}
19+
20+
}
21+
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Runtime.Serialization;
6+
7+
namespace CSMongo.Exceptions {
8+
9+
/// <summary>
10+
/// Thrown when trying to serialize an object to a byte
11+
/// array but the binary formatter fails
12+
/// </summary>
13+
public class MongoSerializationException : ApplicationException {
14+
15+
/// <summary>
16+
/// Throws that an object could not be serialized
17+
/// </summary>
18+
public MongoSerializationException(string type, Exception ex)
19+
: base(string.Format("Couldn't serialize type {0} to a byte array.", type), ex) {
20+
}
21+
22+
}
23+
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using CSMongo.DataTypes;
6+
7+
namespace CSMongo.Exceptions {
8+
9+
/// <summary>
10+
/// Thrown when attempting to register the same MongoDataType
11+
/// more than once
12+
/// </summary>
13+
public class MongoTypeAlreadyRegisteredException : InvalidOperationException {
14+
15+
/// <summary>
16+
/// Throws that the requested type has already been registered
17+
/// </summary>
18+
public MongoTypeAlreadyRegisteredException(Type type)
19+
: base(string.Format("The MongoDataType {0} has already been registered!", type.Name)) {
20+
}
21+
22+
}
23+
24+
}

Exceptions/NoCursorsFoundException.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace CSMongo.Exceptions {
7+
8+
/// <summary>
9+
/// Thrown when attempting to get access to a cursor but
10+
/// the collection has no cursors available
11+
/// </summary>
12+
public class NoCursorsFoundException : InvalidOperationException {
13+
14+
/// <summary>
15+
/// Throws that the collection has no cursors waiting
16+
/// </summary>
17+
public NoCursorsFoundException()
18+
: base("No cursors are available to use. Have you performed any queries yet?") {
19+
}
20+
21+
}
22+
23+
}

0 commit comments

Comments
 (0)