Skip to content

Commit 07f9089

Browse files
Merge pull request #404 from paulomorgado/base-exception
Intorduced RabbitMQClientException as base classe for exceptions.
2 parents c3505b3 + 4d6d652 commit 07f9089

11 files changed

+108
-30
lines changed

projects/client/RabbitMQ.Client/src/client/api/TopologyRecoveryException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@
3939
//---------------------------------------------------------------------------
4040

4141
using System;
42+
using RabbitMQ.Client.Exceptions;
4243

4344
namespace RabbitMQ.Client
4445
{
45-
public class TopologyRecoveryException : Exception
46+
public class TopologyRecoveryException : RabbitMQClientException
4647
{
4748
public TopologyRecoveryException(string message, Exception cause) : base(message, cause)
4849
{

projects/client/RabbitMQ.Client/src/client/exceptions/ChannelAllocationException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ public ChannelAllocationException()
6161
/// </summary>
6262
/// <param name="channel">The requested channel number</param>
6363
public ChannelAllocationException(int channel)
64-
: base(string.Format("The Requested Channel ({0}) is already in use.", channel))
64+
: base($"The Requested Channel ({channel}) is already in use.")
6565
{
6666
Channel = channel;
6767
}
6868

6969
///<summary>Retrieves the channel number concerned; will
7070
///return -1 in the case where "no more free channels" is
71-
///being signalled, or a non-negative integer when "channel is
72-
///in use" is being signalled.</summary>
71+
///being signaled, or a non-negative integer when "channel is
72+
///in use" is being signaled.</summary>
7373
public int Channel { get; private set; }
7474
}
7575
}

projects/client/RabbitMQ.Client/src/client/exceptions/OperationInterruptedException.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,22 @@ namespace RabbitMQ.Client.Exceptions
5151
/// </summary>
5252
public class OperationInterruptedException
5353
// TODO: inherit from OperationCanceledException
54-
: Exception
54+
: RabbitMQClientException
5555
{
5656
///<summary>Construct an OperationInterruptedException with
5757
///the passed-in explanation, if any.</summary>
5858
public OperationInterruptedException(ShutdownEventArgs reason)
5959
: base(reason == null ? "The AMQP operation was interrupted" :
60-
string.Format("The AMQP operation was interrupted: {0}",
61-
reason))
60+
$"The AMQP operation was interrupted: {reason}")
6261
{
6362
ShutdownReason = reason;
6463
}
6564

6665
///<summary>Construct an OperationInterruptedException with
6766
///the passed-in explanation and prefix, if any.</summary>
6867
public OperationInterruptedException(ShutdownEventArgs reason, String prefix)
69-
: base(reason == null ? (prefix + ": The AMQP operation was interrupted") :
70-
string.Format("{0}: The AMQP operation was interrupted: {1}",
71-
prefix, reason))
68+
: base(reason == null ? ($"{prefix}: The AMQP operation was interrupted") :
69+
$"{prefix}: The AMQP operation was interrupted: {reason}")
7270
{
7371
ShutdownReason = reason;
7472
}

projects/client/RabbitMQ.Client/src/client/exceptions/PacketNotRecognizedException.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,14 @@ namespace RabbitMQ.Client.Exceptions
5151
///The peer's {'A','M','Q','P',txHi,txLo,major,minor} packet is
5252
///decoded into instances of this class.
5353
///</remarks>
54-
public class PacketNotRecognizedException : Exception
54+
public class PacketNotRecognizedException : RabbitMQClientException
5555
{
5656
///<summary>Fills the new instance's properties with the values passed in.</summary>
5757
public PacketNotRecognizedException(int transportHigh,
5858
int transportLow,
5959
int serverMajor,
6060
int serverMinor)
61-
: base("AMQP server protocol version " + serverMajor + "-" + serverMinor +
62-
", transport parameters " + transportHigh + ":" + transportLow)
61+
: base($"AMQP server protocol version {serverMajor}-{serverMinor}, transport parameters {transportHigh}:{transportLow}")
6362
{
6463
TransportHigh = transportHigh;
6564
TransportLow = transportLow;

projects/client/RabbitMQ.Client/src/client/exceptions/PossibleAuthenticationFailureException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace RabbitMQ.Client.Exceptions
4444
{
4545
/// <summary> Thrown when the likely cause is an
4646
/// authentication failure. </summary>
47-
public class PossibleAuthenticationFailureException : Exception
47+
public class PossibleAuthenticationFailureException : RabbitMQClientException
4848
{
4949
public PossibleAuthenticationFailureException(String msg, Exception inner) : base(msg, inner)
5050
{

projects/client/RabbitMQ.Client/src/client/exceptions/ProtocolVersionMismatchException.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ public ProtocolVersionMismatchException(int clientMajor,
5353
int clientMinor,
5454
int serverMajor,
5555
int serverMinor)
56-
: base("AMQP server protocol negotiation failure: server version " +
57-
positiveOrUnknown(serverMajor) + "-" + positiveOrUnknown(serverMinor) +
58-
", client version " + positiveOrUnknown(clientMajor) + "-" + positiveOrUnknown(clientMinor))
56+
: base($"AMQP server protocol negotiation failure: server version {positiveOrUnknown(serverMajor)}-{positiveOrUnknown(serverMinor)}, client version {positiveOrUnknown(clientMajor)}-{positiveOrUnknown(clientMinor)}")
5957
{
6058
ClientMajor = clientMajor;
6159
ClientMinor = clientMinor;

projects/client/RabbitMQ.Client/src/client/exceptions/ProtocolViolationException.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@
3838
// Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
3939
//---------------------------------------------------------------------------
4040

41+
using System;
42+
using RabbitMQ.Client.Exceptions;
43+
4144
namespace RabbitMQ.Client
4245
{
43-
public class ProtocolViolationException : System.Exception
46+
public class ProtocolViolationException : RabbitMQClientException
4447
{
4548
public ProtocolViolationException(string message) : base(message)
4649
{
4750
}
48-
public ProtocolViolationException(string message, System.Exception inner) : base(message, inner)
51+
public ProtocolViolationException(string message, Exception inner) : base(message, inner)
4952
{
5053
}
5154
public ProtocolViolationException()
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// This source code is dual-licensed under the Apache License, version
2+
// 2.0, and the Mozilla Public License, version 1.1.
3+
//
4+
// The APL v2.0:
5+
//
6+
//---------------------------------------------------------------------------
7+
// Copyright (c) 2007-2016 Pivotal Software, Inc.
8+
//
9+
// Licensed under the Apache License, Version 2.0 (the "License");
10+
// you may not use this file except in compliance with the License.
11+
// You may obtain a copy of the License at
12+
//
13+
// http://www.apache.org/licenses/LICENSE-2.0
14+
//
15+
// Unless required by applicable law or agreed to in writing, software
16+
// distributed under the License is distributed on an "AS IS" BASIS,
17+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
// See the License for the specific language governing permissions and
19+
// limitations under the License.
20+
//---------------------------------------------------------------------------
21+
//
22+
// The MPL v1.1:
23+
//
24+
//---------------------------------------------------------------------------
25+
// The contents of this file are subject to the Mozilla Public License
26+
// Version 1.1 (the "License"); you may not use this file except in
27+
// compliance with the License. You may obtain a copy of the License
28+
// at http://www.mozilla.org/MPL/
29+
//
30+
// Software distributed under the License is distributed on an "AS IS"
31+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
32+
// the License for the specific language governing rights and
33+
// limitations under the License.
34+
//
35+
// The Original Code is RabbitMQ.
36+
//
37+
// The Initial Developer of the Original Code is Pivotal Software, Inc.
38+
// Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
39+
//---------------------------------------------------------------------------
40+
41+
using System;
42+
43+
namespace RabbitMQ.Client.Exceptions
44+
{
45+
public abstract class RabbitMQClientException : Exception
46+
{
47+
/// <summary>Initializes a new instance of the <see cref="RabbitMQClientException" /> class.</summary>
48+
protected RabbitMQClientException()
49+
{
50+
51+
}
52+
53+
/// <summary>Initializes a new instance of the <see cref="RabbitMQClientException" /> class with a specified error message.</summary>
54+
/// <param name="message">The message that describes the error. </param>
55+
protected RabbitMQClientException(string message) : base(message)
56+
{
57+
58+
}
59+
60+
/// <summary>Initializes a new instance of the <see cref="RabbitMQClientException" /> class with a specified error message and a reference to the inner exception that is the cause of this exception.</summary>
61+
/// <param name="message">The error message that explains the reason for the exception. </param>
62+
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified. </param>
63+
protected RabbitMQClientException(string message, Exception innerException) : base(message, innerException)
64+
{
65+
66+
}
67+
68+
/*
69+
#if !(NETFX_CORE)
70+
/// <summary>Initializes a new instance of the <see cref="RabbitMQClientException" /> class with serialized data.</summary>
71+
/// <param name="info">The <see cref="System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown. </param>
72+
/// <param name="context">The <see cref="System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination. </param>
73+
/// <exception cref="System.ArgumentNullException">The <paramref name="info" /> parameter is null. </exception>
74+
/// <exception cref="System.Runtime.Serialization.SerializationException">The class name is null or <see cref="System.Exception.HResult" /> is zero (0). </exception>
75+
[System.Security.SecuritySafeCritical]
76+
protected RabbitMQClientException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
77+
{
78+
79+
}
80+
#endif
81+
*/
82+
}
83+
}

projects/client/RabbitMQ.Client/src/client/impl/ChannelErrorException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace RabbitMQ.Client.Impl
4949
public class ChannelErrorException : HardProtocolException
5050
{
5151
public ChannelErrorException(int channel)
52-
: base(string.Format("Frame received for invalid channel {0}", channel))
52+
: base($"Frame received for invalid channel {channel}")
5353
{
5454
Channel = channel;
5555
}

projects/client/RabbitMQ.Client/src/client/impl/ProtocolException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@
4040

4141
using System;
4242
using System.Net;
43+
using RabbitMQ.Client.Exceptions;
4344

4445
namespace RabbitMQ.Client.Impl
4546
{
4647
/// <summary> Instances of subclasses of subclasses
4748
/// HardProtocolException and SoftProtocolException are thrown in
4849
/// situations when we detect a problem with the connection-,
4950
/// channel- or wire-level parts of the AMQP protocol. </summary>
50-
public abstract class ProtocolException : Exception
51+
public abstract class ProtocolException : RabbitMQClientException
5152
{
5253
protected ProtocolException(string message) : base(message)
5354
{

0 commit comments

Comments
 (0)