From 0831ab14a6234eb9078e6d902b7ec9532dce11d2 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Mon, 24 Jun 2024 22:21:52 -0400 Subject: [PATCH] Consolidate/refactor local exceptions in C# (#2338) --- CHANGELOG-3.8.md | 31 + cpp/test/Ice/proxy/AllTests.cpp | 12 +- csharp/src/Ice/Communicator.cs | 5 +- csharp/src/Ice/Connection.cs | 2 +- csharp/src/Ice/ConnectionI.cs | 106 +- csharp/src/Ice/CurrentExtensions.cs | 29 +- csharp/src/Ice/Exception.cs | 53 +- csharp/src/Ice/IncomingRequest.cs | 2 +- csharp/src/Ice/InputStream.cs | 131 +- csharp/src/Ice/Internal/BZip2.cs | 10 +- csharp/src/Ice/Internal/Buffer.cs | 4 +- csharp/src/Ice/Internal/ConnectionFactory.cs | 2 +- .../src/Ice/Internal/DefaultsAndOverrides.cs | 4 +- .../Ice/Internal/EndpointFactoryManager.cs | 16 +- csharp/src/Ice/Internal/Ex.cs | 31 +- csharp/src/Ice/Internal/IPEndpointI.cs | 25 +- csharp/src/Ice/Internal/Instance.cs | 14 +- csharp/src/Ice/Internal/LocatorInfo.cs | 16 +- csharp/src/Ice/Internal/Network.cs | 26 +- csharp/src/Ice/Internal/NetworkProxy.cs | 4 +- .../src/Ice/Internal/ObjectAdapterFactory.cs | 5 +- csharp/src/Ice/Internal/OpaqueEndpointI.cs | 29 +- csharp/src/Ice/Internal/OutgoingAsync.cs | 77 +- csharp/src/Ice/Internal/Protocol.cs | 55 +- csharp/src/Ice/Internal/Reference.cs | 14 +- csharp/src/Ice/Internal/ReferenceFactory.cs | 115 +- .../src/Ice/Internal/RequestHandlerCache.cs | 16 +- csharp/src/Ice/Internal/RouterInfo.cs | 2 +- csharp/src/Ice/Internal/ServantManager.cs | 45 +- csharp/src/Ice/Internal/StreamSocket.cs | 4 +- csharp/src/Ice/Internal/TcpEndpointI.cs | 14 +- csharp/src/Ice/Internal/UdpEndpointI.cs | 37 +- csharp/src/Ice/Internal/UdpTransceiver.cs | 4 +- .../src/Ice/Internal/ValueFactoryManager.cs | 5 +- csharp/src/Ice/Internal/WSEndpoint.cs | 4 +- csharp/src/Ice/Internal/WSTransceiver.cs | 10 +- csharp/src/Ice/LocalException.cs | 2038 +---------------- csharp/src/Ice/LocalExceptions.cs | 598 +++++ csharp/src/Ice/LoggerPlugin.cs | 8 +- csharp/src/Ice/Object.cs | 5 +- csharp/src/Ice/ObjectAdapter.cs | 57 +- csharp/src/Ice/OutputStream.cs | 2 +- csharp/src/Ice/PluginManagerI.cs | 75 +- csharp/src/Ice/Properties.cs | 4 +- csharp/src/Ice/Proxy.cs | 6 +- csharp/src/Ice/SSL/RFC2253.cs | 9 - csharp/src/Ice/SSL/SSLEngine.cs | 2 +- csharp/src/Ice/SSL/TransceiverI.cs | 14 +- csharp/src/Ice/SSL/TrustManager.cs | 8 +- csharp/src/Ice/ThreadHookPlugin.cs | 4 +- csharp/src/Ice/UserException.cs | 38 + csharp/src/Ice/Util.cs | 24 +- csharp/src/Ice/UtilInternal/Options.cs | 13 +- csharp/src/Ice/ValueFactory.cs | 4 +- csharp/src/IceBox/Service.cs | 44 +- csharp/src/IceBoxNet/ServiceManagerI.cs | 57 +- csharp/test/Ice/ami/AllTests.cs | 16 +- csharp/test/Ice/background/AllTests.cs | 2 +- csharp/test/Ice/exceptions/AllTests.cs | 12 +- csharp/test/Ice/invoke/BlobjectI.cs | 12 +- csharp/test/Ice/objects/AllTests.cs | 6 +- csharp/test/Ice/operations/BatchOneways.cs | 2 +- csharp/test/Ice/proxy/AllTests.cs | 80 +- .../Ice/servantLocator/ServantLocatorAMDI.cs | 16 +- .../Ice/servantLocator/ServantLocatorI.cs | 16 +- csharp/test/Ice/slicing/objects/AllTests.cs | 15 +- csharp/test/Ice/stream/AllTests.cs | 2 +- csharp/test/Ice/timeout/AllTests.cs | 4 +- csharp/test/IceUtil/inputUtil/Client.cs | 4 +- .../main/java/test/Ice/proxy/AllTests.java | 12 +- swift/test/Ice/proxy/AllTests.swift | 10 +- 71 files changed, 1210 insertions(+), 2968 deletions(-) create mode 100644 csharp/src/Ice/LocalExceptions.cs create mode 100644 csharp/src/Ice/UserException.cs diff --git a/CHANGELOG-3.8.md b/CHANGELOG-3.8.md index f3e0cbf5adc..d53aef1522d 100644 --- a/CHANGELOG-3.8.md +++ b/CHANGELOG-3.8.md @@ -58,6 +58,37 @@ These are the changes since the Ice 3.7.10 release in [CHANGELOG-3.7.md](./CHANG (the unit is seconds). You can also override this value for a specific object adapter with the configuration property `AdapterName.Connection.CloseTimeout`. +- Consolidate and refactor the exceptions derived from LocalException. + | Local exception in Ice 3.7 | Replacement | + |-------------------------------------|----------------------------| + | BadMagicException | ProtocolException (base) | + | CompressionException | ProtocolException (base) | + | ConnectionManuallyClosedException | ConnectionAbortedException, ConnectionClosedException | + | ConnectionNotValidatedException | ProtocolException (base) | + | EncapsulationException | MarshalException (base) | + | EndpointParseException | ParseException | + | EndpointSelectionTypeParseException | ParseException | + | IllegalIdentityException | ArgumentException (C#) | + | IllegalMessageSizeException | MarshalException | + | IllegalServantException | ArgumentNullException (C#) | + | IdentityParseException | ParseException | + | MemoryLimitException | MarshalException (base) | + | NoValueFactoryException | MarshalException (base) | + | ProxyParseException | ParseException | + | ProxyUnmarshalException | MarshalException (base) | + | UnexpectedObjectException | MarshalException (base) | + | UnknownMessageException | ProtocolException (base) | + | UnknownReplyStatusException | MarshalException | + | UnmarshalOutOfBoundsException | MarshalException (base) | + | UnsupportedEncodingException | MarshalException | + | UnsupportedProtocolException | MarshalException, FeatureNotSupportedException | + | VersionParseException | ParseException | + + base = was existing base class + + New local exceptions:\ + ConnectionAbortedException, ConnectionClosedException, ConnectionIdleException, ParseException + ## Slice Language Changes - Removed support for the `["preserve-slice"]` metadata. Slice classes encoded in the Sliced-format are now always diff --git a/cpp/test/Ice/proxy/AllTests.cpp b/cpp/test/Ice/proxy/AllTests.cpp index 9b09e31f19c..f93f1fcb10e 100644 --- a/cpp/test/Ice/proxy/AllTests.cpp +++ b/cpp/test/Ice/proxy/AllTests.cpp @@ -1008,8 +1008,10 @@ allTests(TestHelper* helper) } catch (const Ice::UnknownLocalException& ex) { - // The server thrown an UnsupportedEncodingException - test(ex.unknown.find("UnsupportedEncodingException") != string::npos); + // TODO: remove UnsupportedEncodingException + test( + ex.unknown.find("MarshalException") != string::npos || + ex.unknown.find("UnsupportedEncodingException") != string::npos); } try @@ -1029,8 +1031,10 @@ allTests(TestHelper* helper) } catch (const Ice::UnknownLocalException& ex) { - // The server thrown an UnsupportedEncodingException - test(ex.unknown.find("UnsupportedEncodingException") != string::npos); + // TODO: remove UnsupportedEncodingException + test( + ex.unknown.find("MarshalException") != string::npos || + ex.unknown.find("UnsupportedEncodingException") != string::npos); } cout << "ok" << endl; diff --git a/csharp/src/Ice/Communicator.cs b/csharp/src/Ice/Communicator.cs index 95fd125f406..50227bba3d2 100644 --- a/csharp/src/Ice/Communicator.cs +++ b/csharp/src/Ice/Communicator.cs @@ -85,9 +85,8 @@ public bool isShutdown() /// Converts a stringified proxy into a proxy. /// For example, "MyCategory/MyObject:tcp -h some_host -p 10000" creates a proxy that refers to the Ice object /// having an identity with a name "MyObject" and a category "MyCategory", with the server running on host - /// "some_host", port 10000. If the stringified proxy does not parse correctly, this method throws one of - /// ProxyParseException, EndpointParseException, or IdentityParseException. Refer to the Ice manual for a detailed - /// description of the syntax supported by stringified proxies. + /// "some_host", port 10000. If the stringified proxy does not parse correctly, this method throws ParseException. + /// Refer to the Ice manual for a detailed description of the syntax supported by stringified proxies. /// /// The stringified proxy to convert into a proxy. /// The proxy, or null if str is an empty string. diff --git a/csharp/src/Ice/Connection.cs b/csharp/src/Ice/Connection.cs index 85ced020b5c..bd0f2717fcc 100644 --- a/csharp/src/Ice/Connection.cs +++ b/csharp/src/Ice/Connection.cs @@ -189,7 +189,7 @@ System.Threading.Tasks.Task heartbeatAsync( /// Throw an exception indicating the reason for connection closure. /// For example, /// CloseConnectionException is raised if the connection was closed gracefully, whereas - /// ConnectionManuallyClosedException is raised if the connection was manually closed by + /// ConnectionAbortedException/ConnectionClosedException is raised if the connection was manually closed by /// the application. This operation does nothing if the connection is not yet closed. /// void throwException(); diff --git a/csharp/src/Ice/ConnectionI.cs b/csharp/src/Ice/ConnectionI.cs index ecb94a502be..47ce60c7e03 100644 --- a/csharp/src/Ice/ConnectionI.cs +++ b/csharp/src/Ice/ConnectionI.cs @@ -142,7 +142,7 @@ internal void destroy(int reason) { case ObjectAdapterDeactivated: { - setState(StateClosing, new ObjectAdapterDeactivatedException()); + setState(StateClosing, new ObjectAdapterDeactivatedException(_adapter?.getName() ?? "")); break; } @@ -161,11 +161,18 @@ public void close(ConnectionClose mode) { if (mode == ConnectionClose.Forcefully) { - setState(StateClosed, new ConnectionManuallyClosedException(false)); + setState(StateClosed, + new ConnectionAbortedException( + "Connection close forcefully by the application.", + closedByApplication: true)); } else if (mode == ConnectionClose.Gracefully) { - setState(StateClosing, new ConnectionManuallyClosedException(true)); + setState( + StateClosing, + new ConnectionClosedException( + "Connection close gracefully by the application.", + closedByApplication: true)); } else { @@ -179,7 +186,11 @@ public void close(ConnectionClose mode) Monitor.Wait(this); } - setState(StateClosing, new ConnectionManuallyClosedException(true)); + setState( + StateClosing, + new ConnectionClosedException( + "Connection close gracefully by the application.", + closedByApplication: true)); } } } @@ -884,7 +895,7 @@ public override void message(ref ThreadPoolCurrent current) // // This situation is possible for small UDP packets. // - throw new IllegalMessageSizeException(); + throw new MarshalException("Received Ice message with too few bytes in header."); } // Decode the header. @@ -897,22 +908,29 @@ public override void message(ref ThreadPoolCurrent current) if (m[0] != Protocol.magic[0] || m[1] != Protocol.magic[1] || m[2] != Protocol.magic[2] || m[3] != Protocol.magic[3]) { - BadMagicException ex = new BadMagicException(); - ex.badMagic = m; - throw ex; + throw new ProtocolException( + $"Bad magic in message header: {m[0]:X2} {m[1]:X2} {m[2]:X2} {m[3]:X2}"); } - ProtocolVersion pv = new ProtocolVersion(_readStream); - Protocol.checkSupportedProtocol(pv); - EncodingVersion ev = new EncodingVersion(_readStream); - Protocol.checkSupportedProtocolEncoding(ev); + var pv = new ProtocolVersion(_readStream); + if (pv != Util.currentProtocol) + { + throw new MarshalException( + $"Invalid protocol version in message header: {pv.major}.{pv.minor}"); + } + var ev = new EncodingVersion(_readStream); + if (ev != Util.currentProtocolEncoding) + { + throw new MarshalException( + $"Invalid protocol encoding version in message header: {ev.major}.{ev.minor}"); + } _readStream.readByte(); // messageType _readStream.readByte(); // compress int size = _readStream.readInt(); if (size < Protocol.headerSize) { - throw new IllegalMessageSizeException(); + throw new MarshalException($"Received Ice message with unexpected size {size}."); } // Resize the read buffer to the message size. @@ -1249,7 +1267,7 @@ private void finish() // Trace the cause of unexpected connection closures // if (!(_exception is CloseConnectionException || - _exception is ConnectionManuallyClosedException || + _exception is ConnectionAbortedException || _exception is ConnectionClosedException || _exception is ConnectionIdleException || _exception is CommunicatorDestroyedException || @@ -1507,16 +1525,16 @@ internal void idleCheck(TimeSpan idleTimeout) { if (isActiveOrHolding()) { + int idleTimeoutInSeconds = (int)idleTimeout.TotalSeconds; + if (_instance.traceLevels().network >= 1) { - int idleTimeoutInSeconds = (int)idleTimeout.TotalSeconds; - _instance.initializationData().logger.trace( _instance.traceLevels().networkCat, $"connection aborted by the idle check because it did not receive any bytes for {idleTimeoutInSeconds}s\n{_transceiver.toDetailedString()}"); } - setState(StateClosed, new ConnectionIdleException()); + setState(StateClosed, new ConnectionIdleException($"Connection aborted by the idle check because it did not receive any bytes for {idleTimeoutInSeconds}s.")); } // else nothing to do } @@ -1590,7 +1608,7 @@ private void setState(int state, LocalException ex) // Don't warn about certain expected exceptions. // if (!(_exception is CloseConnectionException || - _exception is ConnectionManuallyClosedException || + _exception is ConnectionAbortedException || _exception is ConnectionClosedException || _exception is ConnectionIdleException || _exception is CommunicatorDestroyedException || @@ -1753,7 +1771,7 @@ private void setState(int state) if (_observer is not null && state == StateClosed && _exception is not null) { if (!(_exception is CloseConnectionException || - _exception is ConnectionManuallyClosedException || + _exception is ConnectionAbortedException || _exception is ConnectionClosedException || _exception is ConnectionIdleException || _exception is CommunicatorDestroyedException || @@ -1921,27 +1939,34 @@ private bool validate(int operation) if (m[0] != Protocol.magic[0] || m[1] != Protocol.magic[1] || m[2] != Protocol.magic[2] || m[3] != Protocol.magic[3]) { - BadMagicException ex = new BadMagicException(); - ex.badMagic = m; - throw ex; + throw new ProtocolException( + $"Bad magic in message header: {m[0]:X2} {m[1]:X2} {m[2]:X2} {m[3]:X2}"); } - ProtocolVersion pv = new ProtocolVersion(_readStream); - Protocol.checkSupportedProtocol(pv); - - EncodingVersion ev = new EncodingVersion(_readStream); - Protocol.checkSupportedProtocolEncoding(ev); + var pv = new ProtocolVersion(_readStream); + if (pv != Util.currentProtocol) + { + throw new MarshalException( + $"Invalid protocol version in message header: {pv.major}.{pv.minor}"); + } + var ev = new EncodingVersion(_readStream); + if (ev != Util.currentProtocolEncoding) + { + throw new MarshalException( + $"Invalid protocol encoding version in message header: {ev.major}.{ev.minor}"); + } byte messageType = _readStream.readByte(); if (messageType != Protocol.validateConnectionMsg) { - throw new ConnectionNotValidatedException(); + throw new ProtocolException( + $"Received message of type {messageType} on connection that is not yet validated."); } _readStream.readByte(); // Ignore compression status for validate connection. int size = _readStream.readInt(); if (size != Protocol.headerSize) { - throw new IllegalMessageSizeException(); + throw new MarshalException($"Received ValidateConnection message with unexpected size {size}."); } TraceUtil.traceRecv(_readStream, _logger, _traceLevels); } @@ -2288,9 +2313,7 @@ private int parseMessage(ref MessageInfo info) else { string lib = AssemblyUtil.isWindows ? "bzip2.dll" : "libbz2.so.1"; - FeatureNotSupportedException ex = new FeatureNotSupportedException(); - ex.unsupportedFeature = "Cannot uncompress compressed message: " + lib + " not found"; - throw ex; + throw new FeatureNotSupportedException($"Cannot uncompress compressed message: {lib} not found"); } } info.stream.pos(Protocol.headerSize); @@ -2364,12 +2387,12 @@ private int parseMessage(ref MessageInfo info) else { TraceUtil.traceRecv(info.stream, _logger, _traceLevels); - info.requestCount = info.stream.readInt(); - if (info.requestCount < 0) + int requestCount = info.stream.readInt(); + if (requestCount < 0) { - info.requestCount = 0; - throw new UnmarshalOutOfBoundsException(); + throw new MarshalException($"Received batch request with {requestCount} batches."); } + info.requestCount = requestCount; info.adapter = _adapter; info.upcallCount += info.requestCount; @@ -2427,7 +2450,8 @@ private int parseMessage(ref MessageInfo info) { TraceUtil.trace("received unknown message\n(invalid, closing connection)", info.stream, _logger, _traceLevels); - throw new UnknownMessageException(); + + throw new ProtocolException($"Received Ice protocol message with unknown type: {messageType}"); } } } @@ -2618,9 +2642,11 @@ private void inactivityCheck(System.Threading.Timer inactivityTimer) if (_state == StateActive) { - // TODO: fix LocalException to accept a message - // "connection closed because it remained inactive for longer than the inactivity timeout" - setState(StateClosing, new ConnectionClosedException()); + setState( + StateClosing, + new ConnectionClosedException( + "Connection closed because it remained inactive for longer than the inactivity timeout.", + closedByApplication: false)); } } // Else this timer was already canceled and disposed. Nothing to do. diff --git a/csharp/src/Ice/CurrentExtensions.cs b/csharp/src/Ice/CurrentExtensions.cs index 98d890ddbc6..cbb8bf42e25 100644 --- a/csharp/src/Ice/CurrentExtensions.cs +++ b/csharp/src/Ice/CurrentExtensions.cs @@ -157,39 +157,32 @@ OutgoingResponse createOutgoingResponseCore(System.Exception exc) _ => throw new Ice.MarshalException("Unexpected exception type") }; - if (rfe.id.name.Length == 0) + Identity id = rfe.id; + string facet = rfe.facet; + if (id.name.Length == 0) { - rfe.id = current.id; + id = current.id; + facet = current.facet; } + string operation = rfe.operation.Length == 0 ? current.operation : rfe.operation; - if (rfe.facet.Length == 0 && current.facet.Length > 0) - { - rfe.facet = current.facet; - } - - if (rfe.operation.Length == 0 && current.operation.Length > 0) - { - rfe.operation = current.operation; - } - - // Called after fixing id, facet and operation. - exceptionMessage = rfe.ToString(); + exceptionMessage = RequestFailedException.createMessage(rfe.GetType().Name, id, facet, operation); if (current.requestId != 0) { ostr.writeByte((byte)replyStatus); - Identity.ice_write(ostr, rfe.id); + Identity.ice_write(ostr, id); - if (rfe.facet.Length == 0) + if (facet.Length == 0) { ostr.writeStringSeq([]); } else { - ostr.writeStringSeq([rfe.facet]); + ostr.writeStringSeq([facet]); } - ostr.writeString(rfe.operation); + ostr.writeString(operation); } break; diff --git a/csharp/src/Ice/Exception.cs b/csharp/src/Ice/Exception.cs index 00d72e6290f..fdbcde294d5 100644 --- a/csharp/src/Ice/Exception.cs +++ b/csharp/src/Ice/Exception.cs @@ -5,62 +5,23 @@ namespace Ice; /// -/// Base class for Ice exceptions. +/// Base class for all Ice exceptions. /// public abstract class Exception : System.Exception { /// - /// Returns the type id of this exception. + /// Returns the type ID of this exception. /// - /// The type id of this exception. + /// The type ID of this exception. public abstract string ice_id(); /// - /// Constructs an Ice exception with an optional inner exception. + /// Constructs an Ice exception. /// + /// The exception message. /// The inner exception. - protected Exception(System.Exception? innerException = null) : base("", innerException) { } -} - -/// -/// Base class for Ice run-time exceptions. -/// -public abstract class LocalException : Exception -{ - /// - /// Constructs an Ice local exception with an optional inner exception. - /// - /// The inner exception. - protected LocalException(System.Exception? innerException = null) : base(innerException) { } -} - -/// -/// Base class for Slice user exceptions. -/// -public abstract class UserException : Exception -{ - public virtual void iceWrite(OutputStream ostr) - { - ostr.startException(); - iceWriteImpl(ostr); - ostr.endException(); - } - - public virtual void iceRead(InputStream istr) + protected Exception(string? message, System.Exception? innerException = null) + : base(message, innerException) { - istr.startException(); - iceReadImpl(istr); - istr.endException(); } - - public virtual bool iceUsesClasses() => false; - - /// - /// Constructs an Ice user exception with an optional inner exception. - /// - /// The inner exception. - protected UserException(System.Exception? innerException = null) : base(innerException) { } - - protected abstract void iceWriteImpl(OutputStream ostr); - protected abstract void iceReadImpl(InputStream istr); } diff --git a/csharp/src/Ice/IncomingRequest.cs b/csharp/src/Ice/IncomingRequest.cs index edc0c2ee62e..3f2555aa131 100644 --- a/csharp/src/Ice/IncomingRequest.cs +++ b/csharp/src/Ice/IncomingRequest.cs @@ -48,7 +48,7 @@ public IncomingRequest(int requestId, Connection? connection, ObjectAdapter adap { if (facetPath.Length > 1) { - throw new Ice.MarshalException(); + throw new MarshalException($"Received invalid facet path with {facetPath.Length} elements."); } facet = facetPath[0]; } diff --git a/csharp/src/Ice/InputStream.cs b/csharp/src/Ice/InputStream.cs index 88375acc396..55b65427d0d 100644 --- a/csharp/src/Ice/InputStream.cs +++ b/csharp/src/Ice/InputStream.cs @@ -313,7 +313,7 @@ public void setLogger(Logger logger) /// /// If true (the default), slicing is enabled; if false, /// slicing is disabled. If slicing is disabled and the stream encounters a Slice type ID - /// during decoding for which no value factory is installed, it raises NoValueFactoryException. + /// during decoding for which no value factory is installed, it raises MarshalException. /// public void setSliceValues(bool b) { @@ -511,11 +511,11 @@ public EncodingVersion startEncapsulation() int sz = readInt(); if (sz < 6) { - throw new UnmarshalOutOfBoundsException(); + throw new MarshalException(endOfBufferMessage); } if (sz - 4 > _buf.b.remaining()) { - throw new UnmarshalOutOfBoundsException(); + throw new MarshalException(endOfBufferMessage); } _encapsStack.sz = sz; @@ -538,14 +538,14 @@ public void endEncapsulation() skipOptionals(); if (_buf.b.position() != _encapsStack.start + _encapsStack.sz) { - throw new EncapsulationException(); + throw new MarshalException("Failed to unmarshal encapsulation."); } } else if (_buf.b.position() != _encapsStack.start + _encapsStack.sz) { if (_buf.b.position() + 1 != _encapsStack.start + _encapsStack.sz) { - throw new EncapsulationException(); + throw new MarshalException("Failed to unmarshal encapsulation."); } // @@ -560,7 +560,7 @@ public void endEncapsulation() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -580,11 +580,11 @@ public EncodingVersion skipEmptyEncapsulation() int sz = readInt(); if (sz < 6) { - throw new EncapsulationException(); + throw new MarshalException($"{sz} is not a valid encapsulation size."); } if (sz - 4 > _buf.b.remaining()) { - throw new UnmarshalOutOfBoundsException(); + throw new MarshalException(endOfBufferMessage); } var encoding = new EncodingVersion(this); @@ -594,7 +594,7 @@ public EncodingVersion skipEmptyEncapsulation() { if (sz != 6) { - throw new EncapsulationException(); + throw new MarshalException($"{sz} is not a valid encapsulation size for a 1.0 empty encapsulation."); } } else @@ -617,12 +617,12 @@ public byte[] readEncapsulation(out EncodingVersion encoding) int sz = readInt(); if (sz < 6) { - throw new UnmarshalOutOfBoundsException(); + throw new MarshalException(endOfBufferMessage); } if (sz - 4 > _buf.b.remaining()) { - throw new UnmarshalOutOfBoundsException(); + throw new MarshalException(endOfBufferMessage); } encoding = new EncodingVersion(this); @@ -636,7 +636,7 @@ public byte[] readEncapsulation(out EncodingVersion encoding) } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -668,7 +668,7 @@ public EncodingVersion skipEncapsulation() int sz = readInt(); if (sz < 6) { - throw new UnmarshalOutOfBoundsException(); + throw new MarshalException(endOfBufferMessage); } EncodingVersion encoding = new EncodingVersion(this); try @@ -677,7 +677,7 @@ public EncodingVersion skipEncapsulation() } catch (ArgumentOutOfRangeException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } return encoding; } @@ -751,7 +751,7 @@ public int readSize() int v = _buf.b.getInt(); if (v < 0) { - throw new UnmarshalOutOfBoundsException(); + throw new MarshalException(endOfBufferMessage); } return v; } @@ -762,7 +762,7 @@ public int readSize() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -813,7 +813,7 @@ public int readAndCheckSeqSize(int minSize) // if (_startSeq + _minSeqSize > _buf.size()) { - throw new UnmarshalOutOfBoundsException(); + throw new MarshalException(endOfBufferMessage); } return sz; @@ -831,7 +831,7 @@ public void readBlob(byte[] v) } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -844,7 +844,7 @@ public byte[] readBlob(int sz) { if (_buf.b.remaining() < sz) { - throw new UnmarshalOutOfBoundsException(); + throw new MarshalException(endOfBufferMessage); } byte[] v = new byte[sz]; try @@ -854,7 +854,7 @@ public byte[] readBlob(int sz) } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -889,7 +889,7 @@ public byte readByte() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -943,7 +943,7 @@ public byte[] readByteSeq() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1051,7 +1051,7 @@ public bool readBool() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1105,7 +1105,7 @@ public bool[] readBoolSeq() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1213,7 +1213,7 @@ public short readShort() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1267,7 +1267,7 @@ public short[] readShortSeq() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1377,7 +1377,7 @@ public int readInt() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1431,7 +1431,7 @@ public int[] readIntSeq() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1466,7 +1466,7 @@ public void readIntSeq(out LinkedList l) } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1493,7 +1493,7 @@ public void readIntSeq(out Queue l) } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1561,7 +1561,7 @@ public long readLong() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1615,7 +1615,7 @@ public long[] readLongSeq() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1650,7 +1650,7 @@ public void readLongSeq(out LinkedList l) } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1677,7 +1677,7 @@ public void readLongSeq(out Queue l) } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1745,7 +1745,7 @@ public float readFloat() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1799,7 +1799,7 @@ public float[] readFloatSeq() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1834,7 +1834,7 @@ public void readFloatSeq(out LinkedList l) } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1861,7 +1861,7 @@ public void readFloatSeq(out Queue l) } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1929,7 +1929,7 @@ public double readDouble() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -1983,7 +1983,7 @@ public double[] readDoubleSeq() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -2018,7 +2018,7 @@ public void readDoubleSeq(out LinkedList l) } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -2045,7 +2045,7 @@ public void readDoubleSeq(out Queue l) } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } } @@ -2121,7 +2121,7 @@ public string readString() // if (_buf.b.remaining() < len) { - throw new UnmarshalOutOfBoundsException(); + throw new MarshalException(endOfBufferMessage); } try @@ -2139,7 +2139,7 @@ public string readString() } catch (InvalidOperationException ex) { - throw new UnmarshalOutOfBoundsException(ex); + throw new MarshalException(endOfBufferMessage, ex); } catch (ArgumentException ex) { @@ -2452,7 +2452,7 @@ public void skip(int size) { if (size < 0 || size > _buf.b.remaining()) { - throw new UnmarshalOutOfBoundsException(); + throw new MarshalException(endOfBufferMessage); } _buf.b.position(_buf.b.position() + size); } @@ -2633,9 +2633,9 @@ private bool skipOptionals() { return (UserException?)_instance!.getActivator().CreateInstance(id); } - catch (Exception ex) + catch (System.Exception ex) { - throw new MarshalException(ex); + throw new MarshalException($"Failed to create user exception with type ID '{id}'.", ex); } } @@ -2703,7 +2703,7 @@ protected string readTypeId(bool isIndex) int index = _stream.readSize(); if (!_typeIdMap.TryGetValue(index, out string? typeId)) { - throw new UnmarshalOutOfBoundsException(); + throw new MarshalException(endOfBufferMessage); } return typeId; } @@ -2749,9 +2749,9 @@ protected string readTypeId(bool isIndex) { v = (Value?)_stream._instance!.getActivator().CreateInstance(typeId); } - catch (Exception ex) + catch (System.Exception ex) { - throw new NoValueFactoryException("no value factory", typeId, ex); + throw new MarshalException($"Failed to create a class with type ID '{typeId}'.", ex); } } @@ -3000,18 +3000,12 @@ internal override void throwException(UserExceptionFactory? factory) { startSlice(); } - catch (UnmarshalOutOfBoundsException ex) + catch (MarshalException) { - // // An oversight in the 1.0 encoding means there is no marker to indicate // the last slice of an exception. As a result, we just try to read the - // next type ID, which raises UnmarshalOutOfBoundsException when the - // input buffer underflows. - // - // Set the reason member to a more helpful message. - // - ex.reason = "unknown exception type `" + mostDerivedId + "'"; - throw; + // next type ID, which raises MarshalException when the input buffer underflows. + throw new MarshalException($"unknown exception type '{mostDerivedId}'"); } } } @@ -3074,7 +3068,7 @@ internal override string startSlice() _sliceSize = _stream.readInt(); if (_sliceSize < 4) { - throw new UnmarshalOutOfBoundsException(); + throw new MarshalException(endOfBufferMessage); } return _typeId; @@ -3154,7 +3148,7 @@ private void readInstance() // if (_typeId == Value.ice_staticId()) { - throw new NoValueFactoryException("", mostDerivedId); + throw new MarshalException($"Cannot find value factory for type ID '{mostDerivedId}'."); } v = newInstance(_typeId); @@ -3172,7 +3166,8 @@ private void readInstance() // if (!_sliceValues) { - throw new NoValueFactoryException("no value factory found and slicing is disabled", _typeId); + throw new MarshalException( + $"Cannot find value factory for type ID '{_typeId}' and slicing is disabled."); } // @@ -3411,7 +3406,7 @@ internal override string startSlice() _current.sliceSize = _stream.readInt(); if (_current.sliceSize < 4) { - throw new UnmarshalOutOfBoundsException(); + throw new MarshalException(endOfBufferMessage); } } else @@ -3505,9 +3500,8 @@ internal override void skipSlice() { if (_current.sliceType == SliceType.ValueSlice) { - throw new NoValueFactoryException("no value factory found and compact format prevents " + - "slicing (the sender should use the sliced format " + - "instead)", _current.typeId); + throw new MarshalException( + $"Cannot find value factory for type ID '{_current.typeId}' and compact format prevents slicing."); } else { @@ -3645,7 +3639,8 @@ private int readInstance(int index, System.Action? cb) // if (!_sliceValues) { - throw new NoValueFactoryException("no value factory found and slicing is disabled", typeId); + throw new MarshalException( + $"Cannot find value factory for type ID '{typeId}' and slicing is disabled."); } // @@ -3864,6 +3859,8 @@ private void initEncaps() private ValueFactoryManager? _valueFactoryManager; private Logger? _logger; + + private const string endOfBufferMessage = "Attempting to unmarshal past the end of the buffer."; } /// diff --git a/csharp/src/Ice/Internal/BZip2.cs b/csharp/src/Ice/Internal/BZip2.cs index b3b65fd2672..783d70ed8db 100644 --- a/csharp/src/Ice/Internal/BZip2.cs +++ b/csharp/src/Ice/Internal/BZip2.cs @@ -316,9 +316,7 @@ public static Buffer compress(Buffer buf, int headerSize, int compressionLevel) } else if (rc < 0) { - Ice.CompressionException ex = new Ice.CompressionException("BZ2_bzBuffToBuffCompress failed"); - ex.reason = getBZ2Error(rc); - throw ex; + throw new ProtocolException($"BZ2_bzBuffToBuffCompress failed: {getBZ2Error(rc)}"); } // @@ -362,7 +360,7 @@ public static Buffer uncompress(Buffer buf, int headerSize, int messageSizeMax) int uncompressedSize = buf.b.getInt(); if (uncompressedSize <= headerSize) { - throw new Ice.IllegalMessageSizeException("compressed size <= header size"); + throw new MarshalException($"Unexpected message size after uncompress: {uncompressedSize}"); } if (uncompressedSize > messageSizeMax) { @@ -377,9 +375,7 @@ public static Buffer uncompress(Buffer buf, int headerSize, int messageSizeMax) int rc = _decompressBuffer(uncompressed, ref uncompressedLen, compressed, compressedLen, 0, 0); if (rc < 0) { - Ice.CompressionException ex = new Ice.CompressionException("BZ2_bzBuffToBuffDecompress failed"); - ex.reason = getBZ2Error(rc); - throw ex; + throw new ProtocolException($"BZ2_bzBuffToBuffDecompress failed: {getBZ2Error(rc)}"); } Buffer r = new Buffer(); diff --git a/csharp/src/Ice/Internal/Buffer.cs b/csharp/src/Ice/Internal/Buffer.cs index 0d71c0ddf5e..6dd7f85a30b 100644 --- a/csharp/src/Ice/Internal/Buffer.cs +++ b/csharp/src/Ice/Internal/Buffer.cs @@ -191,9 +191,7 @@ private void reserve(int n) catch (System.Exception ex) { _capacity = b.capacity(); // Restore the previous capacity. - Ice.MarshalException e = new Ice.MarshalException(ex); - e.reason = "unexpected exception while trying to allocate a ByteBuffer:\n" + ex; - throw e; + throw new MarshalException("unexpected exception while trying to allocate a ByteBuffer", ex); } finally { diff --git a/csharp/src/Ice/Internal/ConnectionFactory.cs b/csharp/src/Ice/Internal/ConnectionFactory.cs index 03cf20a40fd..57aeb3d1e2d 100644 --- a/csharp/src/Ice/Internal/ConnectionFactory.cs +++ b/csharp/src/Ice/Internal/ConnectionFactory.cs @@ -1552,7 +1552,7 @@ public IncomingConnectionFactory(Instance instance, EndpointI endpoint, Endpoint } else { - throw new Ice.SyscallException(ex); + throw new SyscallException(ex); } } } diff --git a/csharp/src/Ice/Internal/DefaultsAndOverrides.cs b/csharp/src/Ice/Internal/DefaultsAndOverrides.cs index b3217ebce5d..a5487682522 100644 --- a/csharp/src/Ice/Internal/DefaultsAndOverrides.cs +++ b/csharp/src/Ice/Internal/DefaultsAndOverrides.cs @@ -82,9 +82,7 @@ internal DefaultsAndOverrides(Ice.Properties properties, Ice.Logger logger) } else { - Ice.EndpointSelectionTypeParseException ex = new Ice.EndpointSelectionTypeParseException(); - ex.str = "illegal value `" + val + "'; expected `Random' or `Ordered'"; - throw ex; + throw new ParseException($"illegal value '{val}' in property Ice.Default.EndpointSelection; expected 'Random' or 'Ordered'"); } defaultLocatorCacheTimeout = properties.getIcePropertyAsInt("Ice.Default.LocatorCacheTimeout"); diff --git a/csharp/src/Ice/Internal/EndpointFactoryManager.cs b/csharp/src/Ice/Internal/EndpointFactoryManager.cs index dea9be2d2e5..e767c630b77 100644 --- a/csharp/src/Ice/Internal/EndpointFactoryManager.cs +++ b/csharp/src/Ice/Internal/EndpointFactoryManager.cs @@ -54,16 +54,12 @@ public EndpointI create(string str, bool oaEndpoint) string[] arr = Ice.UtilInternal.StringUtil.splitString(str, " \t\r\n"); if (arr == null) { - Ice.EndpointParseException e = new Ice.EndpointParseException(); - e.str = "mismatched quote"; - throw e; + throw new ParseException($"Failed to parse endpoint '{str}': mismatched quote"); } if (arr.Length == 0) { - Ice.EndpointParseException e = new Ice.EndpointParseException(); - e.str = "value has no non-whitespace characters"; - throw e; + throw new ParseException($"Failed to parse endpoint '{str}': value has no non-whitespace characters"); } List v = new List(arr); @@ -94,9 +90,7 @@ public EndpointI create(string str, bool oaEndpoint) EndpointI e = factory.create(v, oaEndpoint); if (v.Count > 0) { - Ice.EndpointParseException ex = new Ice.EndpointParseException(); - ex.str = "unrecognized argument `" + v[0] + "' in endpoint `" + str + "'"; - throw ex; + throw new ParseException($"Failed to parse endpoint '{str}': unrecognized argument '{v[0]}'"); } return e; @@ -125,9 +119,7 @@ public EndpointI create(string str, bool oaEndpoint) EndpointI ue = new OpaqueEndpointI(v); if (v.Count > 0) { - Ice.EndpointParseException ex = new Ice.EndpointParseException(); - ex.str = "unrecognized argument `" + v[0] + "' in endpoint `" + str + "'"; - throw ex; + throw new ParseException($"Failed to parse endpoint '{str}': unrecognized argument '{v[0]}'"); } factory = get(ue.type()); if (factory != null) diff --git a/csharp/src/Ice/Internal/Ex.cs b/csharp/src/Ice/Internal/Ex.cs index 5b49ca2ba8f..fab1927d19a 100644 --- a/csharp/src/Ice/Internal/Ex.cs +++ b/csharp/src/Ice/Internal/Ex.cs @@ -8,15 +8,10 @@ public static class Ex { public static void throwUOE(Type expectedType, Ice.Value v) { - // - // If the object is an unknown sliced object, we didn't find an - // value factory, in this case raise a NoValueFactoryException - // instead. - // - if (v is Ice.UnknownSlicedValue) + // If the object is an unknown sliced object, we didn't find an value factory. + if (v is UnknownSlicedValue usv) { - Ice.UnknownSlicedValue usv = (Ice.UnknownSlicedValue)v; - throw new Ice.NoValueFactoryException("", usv.ice_id()); + throw new MarshalException($"Cannot find value factory to unmarshal class with type ID `{usv.ice_id()}'."); } string type = v.ice_id(); @@ -31,28 +26,22 @@ public static void throwUOE(Type expectedType, Ice.Value v) Debug.Assert(false); } - throw new Ice.UnexpectedObjectException("expected element of type `" + expected + "' but received `" + - type + "'", type, expected); + throw new MarshalException( + $"Failed to unmarshal class with type ID '{expected}': value factory returned class with type ID '{type}'."); } public static void throwMemoryLimitException(int requested, int maximum) { - throw new Ice.MemoryLimitException("requested " + requested + " bytes, maximum allowed is " + maximum + - " bytes (see Ice.MessageSizeMax)"); + throw new MarshalException( + $"Cannot unmarshal Ice message: the message size of {requested} bytes exceeds the maximum allowed of {maximum} bytes (see Ice.MessageSizeMax)."); } } public class RetryException : System.Exception { - public RetryException(Ice.LocalException ex) - { - _ex = ex; - } + private readonly Ice.LocalException _ex; - public Ice.LocalException get() - { - return _ex; - } + public RetryException(Ice.LocalException ex) => _ex = ex; - private Ice.LocalException _ex; + public Ice.LocalException get() => _ex; } diff --git a/csharp/src/Ice/Internal/IPEndpointI.cs b/csharp/src/Ice/Internal/IPEndpointI.cs index 282c9d0ab51..50362876a86 100644 --- a/csharp/src/Ice/Internal/IPEndpointI.cs +++ b/csharp/src/Ice/Internal/IPEndpointI.cs @@ -314,7 +314,7 @@ public virtual void initWithOptions(List args, bool oaEndpoint) } else { - throw new Ice.EndpointParseException("`-h *' not valid for proxy endpoint `" + ToString() + "'"); + throw new ParseException($"'-h *' not valid for proxy endpoint '{ToString()}'"); } } @@ -327,8 +327,7 @@ public virtual void initWithOptions(List args, bool oaEndpoint) { if (oaEndpoint) { - throw new Ice.EndpointParseException("`--sourceAddress' not valid for object adapter endpoint `" + - ToString() + "'"); + throw new ParseException($"'--sourceAddress' not valid for object adapter endpoint '{ToString()}'"); } } else if (!oaEndpoint) @@ -343,8 +342,7 @@ protected override bool checkOption(string option, string argument, string endpo { if (argument == null) { - throw new Ice.EndpointParseException("no argument provided for -h option in endpoint " + - endpoint); + throw new ParseException($"no argument provided for -h option in endpoint '{endpoint}'"); } host_ = argument; } @@ -352,8 +350,7 @@ protected override bool checkOption(string option, string argument, string endpo { if (argument == null) { - throw new Ice.EndpointParseException("no argument provided for -p option in endpoint " + - endpoint); + throw new ParseException($"no argument provided for -p option in endpoint '{endpoint}'"); } try @@ -362,29 +359,25 @@ protected override bool checkOption(string option, string argument, string endpo } catch (FormatException ex) { - Ice.EndpointParseException e = new Ice.EndpointParseException(ex); - e.str = "invalid port value `" + argument + "' in endpoint " + endpoint; - throw e; + throw new ParseException($"invalid port value '{argument}' in endpoint '{endpoint}'", ex); } if (port_ < 0 || port_ > 65535) { - throw new Ice.EndpointParseException("port value `" + argument + - "' out of range in endpoint " + endpoint); + throw new ParseException($"port value '{argument}' out of range in endpoint '{endpoint}'"); } } else if (option == "--sourceAddress") { if (argument == null) { - throw new Ice.EndpointParseException("no argument provided for --sourceAddress option in endpoint " + - endpoint); + throw new ParseException($"no argument provided for --sourceAddress option in endpoint '{endpoint}'"); } sourceAddr_ = Network.getNumericAddress(argument); if (sourceAddr_ == null) { - throw new Ice.EndpointParseException( - "invalid IP address provided for --sourceAddress option in endpoint " + endpoint); + throw new ParseException( + $"invalid IP address provided for --sourceAddress option in endpoint '{endpoint}'"); } } else diff --git a/csharp/src/Ice/Internal/Instance.cs b/csharp/src/Ice/Internal/Instance.cs index 5d686f65fa7..c7c76728952 100644 --- a/csharp/src/Ice/Internal/Instance.cs +++ b/csharp/src/Ice/Internal/Instance.cs @@ -335,7 +335,7 @@ public Ice.ObjectPrx createAdmin(Ice.ObjectAdapter adminAdapter, Ice.Identity ad if (adminIdentity == null || adminIdentity.name.Length == 0) { - throw new Ice.IllegalIdentityException(adminIdentity); + throw new ArgumentException("The admin identity is not valid", nameof(adminIdentity)); } if (_adminAdapter != null) @@ -655,11 +655,9 @@ internal void initialize(Ice.Communicator communicator, Ice.InitializationData i { outStream = System.IO.File.AppendText(stdOut); } - catch (System.IO.IOException ex) + catch (IOException ex) { - Ice.FileException fe = new Ice.FileException(ex); - fe.path = stdOut; - throw fe; + throw new FileException($"Cannot append to '{stdOut}'", ex); } outStream.AutoFlush = true; Console.Out.Close(); @@ -678,11 +676,9 @@ internal void initialize(Ice.Communicator communicator, Ice.InitializationData i { errStream = System.IO.File.AppendText(stdErr); } - catch (System.IO.IOException ex) + catch (IOException ex) { - Ice.FileException fe = new Ice.FileException(ex); - fe.path = stdErr; - throw fe; + throw new FileException($"Cannot append to '{stdErr}'", ex); } errStream.AutoFlush = true; Console.Error.Close(); diff --git a/csharp/src/Ice/Internal/LocatorInfo.cs b/csharp/src/Ice/Internal/LocatorInfo.cs index fdd5ace04b9..92e6faa0838 100644 --- a/csharp/src/Ice/Internal/LocatorInfo.cs +++ b/csharp/src/Ice/Internal/LocatorInfo.cs @@ -449,7 +449,7 @@ private void getEndpointsException(Reference @ref, System.Exception exc) { throw exc; } - catch (Ice.AdapterNotFoundException ex) + catch (Ice.AdapterNotFoundException) { Instance instance = @ref.getInstance(); if (instance.traceLevels().location >= 1) @@ -460,12 +460,9 @@ private void getEndpointsException(Reference @ref, System.Exception exc) instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.ToString()); } - Ice.NotRegisteredException e = new Ice.NotRegisteredException(ex); - e.kindOfObject = "object adapter"; - e.id = @ref.getAdapterId(); - throw e; + throw new NotRegisteredException("object adapter", @ref.getAdapterId()); } - catch (Ice.ObjectNotFoundException ex) + catch (Ice.ObjectNotFoundException) { Instance instance = @ref.getInstance(); if (instance.traceLevels().location >= 1) @@ -476,10 +473,9 @@ private void getEndpointsException(Reference @ref, System.Exception exc) instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.ToString()); } - Ice.NotRegisteredException e = new Ice.NotRegisteredException(ex); - e.kindOfObject = "object"; - e.id = Ice.Util.identityToString(@ref.getIdentity(), instance.toStringMode()); - throw e; + throw new NotRegisteredException( + "object", + Ice.Util.identityToString(@ref.getIdentity(), instance.toStringMode())); } catch (Ice.NotRegisteredException) { diff --git a/csharp/src/Ice/Internal/Network.cs b/csharp/src/Ice/Internal/Network.cs index 573ccf00b9f..9e92e31cade 100644 --- a/csharp/src/Ice/Internal/Network.cs +++ b/csharp/src/Ice/Internal/Network.cs @@ -748,9 +748,7 @@ public static List getAddresses(string host, int port, int protocol, } else { - Ice.DNSException e = new Ice.DNSException(); - e.host = host; - throw e; + throw new DNSException(host); } } catch (FormatException) @@ -793,15 +791,11 @@ public static List getAddresses(string host, int port, int protocol, { goto repeatGetHostByName; } - Ice.DNSException e = new Ice.DNSException(ex); - e.host = host; - throw e; + throw new DNSException(host, ex); } catch (System.Exception ex) { - Ice.DNSException e = new Ice.DNSException(ex); - e.host = host; - throw e; + throw new DNSException(host, ex); } // @@ -809,9 +803,7 @@ public static List getAddresses(string host, int port, int protocol, // if (addresses.Count == 0) { - Ice.DNSException e = new Ice.DNSException(); - e.host = host; - throw e; + throw new DNSException(host); } return addresses; } @@ -854,15 +846,11 @@ public static IPAddress[] getLocalAddresses(int protocol, bool includeLoopback, { goto repeatGetHostByName; } - Ice.DNSException e = new Ice.DNSException(ex); - e.host = "0.0.0.0"; - throw e; + throw new DNSException("0.0.0.0", ex); } catch (System.Exception ex) { - Ice.DNSException e = new Ice.DNSException(ex); - e.host = "0.0.0.0"; - throw e; + throw new DNSException("0.0.0.0", ex); } return addresses.ToArray(); @@ -1200,7 +1188,7 @@ private static int // // The iface parameter must either be an IP address, an // index or the name of an interface. If it's an index we - // just return it. If it's an IP addess we search for an + // just return it. If it's an IP address we search for an // interface which has this IP address. If it's a name we // search an interface with this name. // diff --git a/csharp/src/Ice/Internal/NetworkProxy.cs b/csharp/src/Ice/Internal/NetworkProxy.cs index cfecb84ab93..9e673a8b974 100644 --- a/csharp/src/Ice/Internal/NetworkProxy.cs +++ b/csharp/src/Ice/Internal/NetworkProxy.cs @@ -74,11 +74,11 @@ public void beginWrite(EndPoint endpoint, Buffer buf) { if (!(endpoint is IPEndPoint)) { - throw new Ice.FeatureNotSupportedException("SOCKS4 does not support domain names"); + throw new FeatureNotSupportedException("SOCKS4 does not support domain names."); } else if (endpoint.AddressFamily != AddressFamily.InterNetwork) { - throw new Ice.FeatureNotSupportedException("SOCKS4 only supports IPv4 addresses"); + throw new FeatureNotSupportedException("SOCKS4 only supports IPv4 addresses."); } // diff --git a/csharp/src/Ice/Internal/ObjectAdapterFactory.cs b/csharp/src/Ice/Internal/ObjectAdapterFactory.cs index 594e4149362..33e54358e76 100644 --- a/csharp/src/Ice/Internal/ObjectAdapterFactory.cs +++ b/csharp/src/Ice/Internal/ObjectAdapterFactory.cs @@ -140,10 +140,7 @@ public Ice.ObjectAdapter createObjectAdapter( { if (_adapterNamesInUse.Contains(name)) { - Ice.AlreadyRegisteredException ex = new Ice.AlreadyRegisteredException(); - ex.kindOfObject = "object adapter"; - ex.id = name; - throw ex; + throw new AlreadyRegisteredException("object adapter", name); } _adapterNamesInUse.Add(name); } diff --git a/csharp/src/Ice/Internal/OpaqueEndpointI.cs b/csharp/src/Ice/Internal/OpaqueEndpointI.cs index 43280166711..9a2285e9976 100644 --- a/csharp/src/Ice/Internal/OpaqueEndpointI.cs +++ b/csharp/src/Ice/Internal/OpaqueEndpointI.cs @@ -18,11 +18,11 @@ public OpaqueEndpointI(List args) if (_type < 0) { - throw new Ice.EndpointParseException("no -t option in endpoint " + ToString()); + throw new ParseException($"no -t option in endpoint '{this}'"); } if (_rawBytes.Length == 0) { - throw new Ice.EndpointParseException("no -v option in endpoint " + ToString()); + throw new ParseException($"no -v option in endpoint '{this}'"); } } @@ -336,11 +336,11 @@ protected override bool checkOption(string option, string argument, string endpo { if (_type > -1) { - throw new Ice.EndpointParseException("multiple -t options in endpoint " + endpoint); + throw new ParseException($"multiple -t options in endpoint '{endpoint}'"); } if (argument == null) { - throw new Ice.EndpointParseException("no argument provided for -t option in endpoint " + endpoint); + throw new ParseException($"no argument provided for -t option in endpoint '{endpoint}'"); } int t; @@ -348,16 +348,14 @@ protected override bool checkOption(string option, string argument, string endpo { t = System.Int32.Parse(argument, CultureInfo.InvariantCulture); } - catch (System.FormatException) + catch (FormatException ex) { - throw new Ice.EndpointParseException("invalid type value `" + argument + "' in endpoint " + - endpoint); + throw new ParseException($"invalid type value '{argument}' in endpoint '{endpoint}'", ex); } if (t < 0 || t > 65535) { - throw new Ice.EndpointParseException("type value `" + argument + "' out of range in endpoint " + - endpoint); + throw new ParseException($"type value '{argument}' out of range in endpoint '{endpoint}'"); } _type = (short)t; @@ -368,11 +366,11 @@ protected override bool checkOption(string option, string argument, string endpo { if (_rawBytes.Length > 0) { - throw new Ice.EndpointParseException("multiple -v options in endpoint " + endpoint); + throw new ParseException($"multiple -v options in endpoint '{endpoint}'"); } if (argument == null) { - throw new Ice.EndpointParseException("no argument provided for -v option in endpoint " + endpoint); + throw new ParseException($"no argument provided for -v option in endpoint '{endpoint}'"); } try @@ -381,7 +379,7 @@ protected override bool checkOption(string option, string argument, string endpo } catch (System.FormatException ex) { - throw new Ice.EndpointParseException("Invalid Base64 input in endpoint " + endpoint, ex); + throw new ParseException($"invalid Base64 input in endpoint '{endpoint}'", ex); } return true; @@ -391,17 +389,16 @@ protected override bool checkOption(string option, string argument, string endpo { if (argument == null) { - throw new Ice.EndpointParseException("no argument provided for -e option in endpoint " + endpoint); + throw new ParseException($"no argument provided for -e option in endpoint '{endpoint}'"); } try { _rawEncoding = Ice.Util.stringToEncodingVersion(argument); } - catch (Ice.VersionParseException e) + catch (ParseException e) { - throw new Ice.EndpointParseException("invalid encoding version `" + argument + - "' in endpoint " + endpoint + ":\n" + e.str); + throw new ParseException($"invalid encoding version '{argument}' in endpoint '{endpoint}'", e); } return true; } diff --git a/csharp/src/Ice/Internal/OutgoingAsync.cs b/csharp/src/Ice/Internal/OutgoingAsync.cs index a3c59ae1a57..30f0f9e3189 100644 --- a/csharp/src/Ice/Internal/OutgoingAsync.cs +++ b/csharp/src/Ice/Internal/OutgoingAsync.cs @@ -643,7 +643,11 @@ public OutgoingAsync(Ice.ObjectPrxHelperBase prx, OutgoingAsyncCompletionCallbac public void prepare(string operation, Ice.OperationMode mode, Dictionary context) { - Protocol.checkSupportedProtocol(Protocol.getCompatibleProtocol(proxy_.iceReference().getProtocol())); + if (proxy_.iceReference().getProtocol().major != Ice.Util.currentProtocol.major) + { + throw new FeatureNotSupportedException( + $"Cannot send request using protocol version {proxy_.iceReference().getProtocol()}."); + } mode_ = mode; @@ -756,13 +760,12 @@ public override bool response() // For compatibility with the old FacetPath. // string[] facetPath = is_.readStringSeq(); - ; string facet; if (facetPath.Length > 0) { if (facetPath.Length > 1) { - throw new Ice.MarshalException(); + throw new MarshalException($"Received invalid facet path with {facetPath.Length} elements."); } facet = facetPath[0]; } @@ -772,82 +775,44 @@ public override bool response() } string operation = is_.readString(); - - Ice.RequestFailedException ex = null; switch (replyStatus) { case ReplyStatus.ObjectNotExist: - { - ex = new Ice.ObjectNotExistException(); - break; - } + throw new ObjectNotExistException(ident, facet, operation); case ReplyStatus.FacetNotExist: - { - ex = new Ice.FacetNotExistException(); - break; - } + throw new FacetNotExistException(ident, facet, operation); case ReplyStatus.OperationNotExist: - { - ex = new Ice.OperationNotExistException(); - break; - } - - default: - { - Debug.Assert(false); - break; - } + throw new OperationNotExistException(ident, facet, operation); } - - ex.id = ident; - ex.facet = facet; - ex.operation = operation; - throw ex; + Debug.Assert(false); + break; } case ReplyStatus.UnknownException: case ReplyStatus.UnknownLocalException: case ReplyStatus.UnknownUserException: { - string unknown = is_.readString(); - - Ice.UnknownException ex = null; + string message = is_.readString(); switch (replyStatus) { case ReplyStatus.UnknownException: - { - ex = new Ice.UnknownException(); - break; - } + throw new UnknownException(message); case ReplyStatus.UnknownLocalException: - { - ex = new Ice.UnknownLocalException(); - break; - } + throw new UnknownLocalException(message); case ReplyStatus.UnknownUserException: - { - ex = new Ice.UnknownUserException(); - break; - } - - default: - { - Debug.Assert(false); - break; - } + throw new UnknownUserException(message); } - - ex.unknown = unknown; - throw ex; + Debug.Assert(false); + break; } default: { - throw new Ice.UnknownReplyStatusException(); + throw new MarshalException($"Received reply message with unknown reply status {replyStatus}."); } } @@ -1095,7 +1060,11 @@ public override int invokeCollocated(CollocatedRequestHandler handler) public void invoke(string operation, bool synchronous) { - Protocol.checkSupportedProtocol(Protocol.getCompatibleProtocol(proxy_.iceReference().getProtocol())); + if (proxy_.iceReference().getProtocol().major != Ice.Util.currentProtocol.major) + { + throw new FeatureNotSupportedException( + $"Cannot send request using protocol version {proxy_.iceReference().getProtocol()}."); + } synchronous_ = synchronous; observer_ = ObserverHelper.get(proxy_, operation, null); // Not used for proxy flush batch requests. diff --git a/csharp/src/Ice/Internal/Protocol.cs b/csharp/src/Ice/Internal/Protocol.cs index bd44550d38c..7a62596e4c0 100644 --- a/csharp/src/Ice/Internal/Protocol.cs +++ b/csharp/src/Ice/Internal/Protocol.cs @@ -85,55 +85,12 @@ public sealed class Protocol 0, 0, 0, 0 // Message size (placeholder). }; - internal static void - checkSupportedProtocol(Ice.ProtocolVersion v) - { - if (v.major != protocolMajor || v.minor > protocolMinor) - { - throw new Ice.UnsupportedProtocolException("", v, Ice.Util.currentProtocol); - } - } - - public static void - checkSupportedProtocolEncoding(Ice.EncodingVersion v) - { - if (v.major != protocolEncodingMajor || v.minor > protocolEncodingMinor) - { - throw new Ice.UnsupportedEncodingException("", v, Ice.Util.currentProtocolEncoding); - } - } - - internal static void - checkSupportedEncoding(Ice.EncodingVersion v) + internal static void checkSupportedEncoding(Ice.EncodingVersion v) { if (v.major != encodingMajor || v.minor > encodingMinor) { - throw new Ice.UnsupportedEncodingException("", v, Ice.Util.currentEncoding); - } - } - - // - // Either return the given protocol if not compatible, or the greatest - // supported protocol otherwise. - // - internal static Ice.ProtocolVersion - getCompatibleProtocol(Ice.ProtocolVersion v) - { - if (v.major != Ice.Util.currentProtocol.major) - { - return v; // Unsupported protocol, return as is. - } - else if (v.minor < Ice.Util.currentProtocol.minor) - { - return v; // Supported protocol. - } - else - { - // - // Unsupported but compatible, use the currently supported - // protocol, that's the best we can do. - // - return Ice.Util.currentProtocol; + throw new MarshalException( + $"This Ice runtime does not support encoding version {v.major}.{v.minor}"); } } @@ -162,12 +119,6 @@ internal static Ice.EncodingVersion } } - internal static bool - isSupported(Ice.ProtocolVersion version, Ice.ProtocolVersion supported) - { - return version.major == supported.major && version.minor <= supported.minor; - } - internal static bool isSupported(Ice.EncodingVersion version, Ice.EncodingVersion supported) { diff --git a/csharp/src/Ice/Internal/Reference.cs b/csharp/src/Ice/Internal/Reference.cs index d185509c3c4..49d497febe0 100644 --- a/csharp/src/Ice/Internal/Reference.cs +++ b/csharp/src/Ice/Internal/Reference.cs @@ -659,7 +659,7 @@ internal override RequestHandler getRequestHandler() { if (_fixedConnection.endpoint().datagram()) { - throw new Ice.NoEndpointException(ToString()); + throw new NoEndpointException(new ObjectPrxHelper(this)); } break; } @@ -669,7 +669,7 @@ internal override RequestHandler getRequestHandler() { if (!_fixedConnection.endpoint().datagram()) { - throw new Ice.NoEndpointException(ToString()); + throw new NoEndpointException(new ObjectPrxHelper(this)); } break; } @@ -691,7 +691,7 @@ internal override RequestHandler getRequestHandler() } if (secure && !_fixedConnection.endpoint().secure()) { - throw new Ice.NoEndpointException(ToString()); + throw new NoEndpointException(new ObjectPrxHelper(this)); } _fixedConnection.throwException(); // Throw in case our connection is already destroyed. @@ -1188,7 +1188,7 @@ public void setEndpoints(EndpointI[] endpoints, bool cached) { if (endpoints.Length == 0) { - _cb.setException(new Ice.NoEndpointException(_ir.ToString())); + _cb.setException(new NoEndpointException(new ObjectPrxHelper(_ir))); return; } @@ -1225,7 +1225,7 @@ public void setException(Ice.LocalException exc) { throw exc; } - catch (Ice.NoEndpointException ex) + catch (NoEndpointException ex) { _cb.setException(ex); // No need to retry if there's no endpoints. } @@ -1268,7 +1268,7 @@ private void getConnectionNoRouterInfo(GetConnectionCallback callback) } else { - callback.setException(new Ice.NoEndpointException(ToString())); + callback.setException(new NoEndpointException(new ObjectPrxHelper(this))); } } @@ -1509,7 +1509,7 @@ protected void createConnection(EndpointI[] allEndpoints, GetConnectionCallback EndpointI[] endpoints = filterEndpoints(allEndpoints); if (endpoints.Length == 0) { - callback.setException(new Ice.NoEndpointException(ToString())); + callback.setException(new NoEndpointException(new ObjectPrxHelper(this))); return; } diff --git a/csharp/src/Ice/Internal/ReferenceFactory.cs b/csharp/src/Ice/Internal/ReferenceFactory.cs index 652dd9a8101..c5786bd6417 100644 --- a/csharp/src/Ice/Internal/ReferenceFactory.cs +++ b/csharp/src/Ice/Internal/ReferenceFactory.cs @@ -85,9 +85,7 @@ public Reference create(string s, string propertyPrefix) beg = Ice.UtilInternal.StringUtil.findFirstNotOf(s, delim, end); if (beg == -1) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "no non-whitespace characters found in `" + s + "'"; - throw e; + throw new ParseException($"no non-whitespace characters found in proxy string '{s}'"); } // @@ -98,9 +96,7 @@ public Reference create(string s, string propertyPrefix) end = Ice.UtilInternal.StringUtil.checkQuote(s, beg); if (end == -1) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "mismatched quotes around identity in `" + s + "'"; - throw e; + throw new ParseException($"mismatched quotes around identity in proxy string '{s}'"); } else if (end == 0) { @@ -120,13 +116,11 @@ public Reference create(string s, string propertyPrefix) if (beg == end) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "no identity in `" + s + "'"; - throw e; + throw new ParseException($"no identity in proxy string '{s}'"); } // - // Parsing the identity may raise IdentityParseException. + // Parsing the identity may raise ParseException. // Ice.Identity ident = Ice.Util.stringToIdentity(idstr); @@ -138,9 +132,7 @@ public Reference create(string s, string propertyPrefix) // if (ident.category.Length > 0) { - Ice.IllegalIdentityException e = new Ice.IllegalIdentityException(); - e.id = ident; - throw e; + throw new ParseException("The category of a null Ice object identity must be empty."); } // // Treat a stringified proxy containing two double @@ -150,9 +142,7 @@ public Reference create(string s, string propertyPrefix) // else if (Ice.UtilInternal.StringUtil.findFirstNotOf(s, delim, end) != -1) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "invalid characters after identity in `" + s + "'"; - throw e; + throw new ParseException($"invalid characters after identity in proxy string '{s}'"); } else { @@ -194,9 +184,7 @@ public Reference create(string s, string propertyPrefix) string option = s.Substring(beg, end - beg); if (option.Length != 2 || option[0] != '-') { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "expected a proxy option but found `" + option + "' in `" + s + "'"; - throw e; + throw new ParseException($"expected a proxy option but found '{option}' in proxy string '{s}'"); } // @@ -215,9 +203,7 @@ public Reference create(string s, string propertyPrefix) end = Ice.UtilInternal.StringUtil.checkQuote(s, beg); if (end == -1) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "mismatched quotes around value for " + option + " option in `" + s + "'"; - throw e; + throw new ParseException($"mismatched quotes around value for '{option}' option in proxy string '{s}'"); } else if (end == 0) { @@ -247,9 +233,7 @@ public Reference create(string s, string propertyPrefix) { if (argument == null) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "no argument provided for -f option in `" + s + "'"; - throw e; + throw new ParseException($"no argument provided for -f option in proxy string '{s}'"); } try @@ -258,9 +242,7 @@ public Reference create(string s, string propertyPrefix) } catch (ArgumentException argEx) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "invalid facet in `" + s + "': " + argEx.Message; - throw e; + throw new ParseException($"invalid facet in proxy string '{s}'", argEx); } break; } @@ -269,9 +251,7 @@ public Reference create(string s, string propertyPrefix) { if (argument != null) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "unexpected argument `" + argument + "' provided for -t option in `" + s + "'"; - throw e; + throw new ParseException($"unexpected argument '{argument}' provided for -t option in proxy string '{s}'"); } mode = Reference.Mode.ModeTwoway; break; @@ -281,9 +261,7 @@ public Reference create(string s, string propertyPrefix) { if (argument != null) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "unexpected argument `" + argument + "' provided for -o option in `" + s + "'"; - throw e; + throw new ParseException($"unexpected argument '{argument}' provided for -o option in proxy string '{s}'"); } mode = Reference.Mode.ModeOneway; break; @@ -293,9 +271,7 @@ public Reference create(string s, string propertyPrefix) { if (argument != null) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "unexpected argument `" + argument + "' provided for -O option in `" + s + "'"; - throw e; + throw new ParseException($"unexpected argument '{argument}' provided for -O option in proxy string '{s}'"); } mode = Reference.Mode.ModeBatchOneway; break; @@ -305,9 +281,7 @@ public Reference create(string s, string propertyPrefix) { if (argument != null) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "unexpected argument `" + argument + "' provided for -d option in `" + s + "'"; - throw e; + throw new ParseException($"unexpected argument '{argument}' provided for -d option in proxy string '{s}'"); } mode = Reference.Mode.ModeDatagram; break; @@ -317,9 +291,7 @@ public Reference create(string s, string propertyPrefix) { if (argument != null) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "unexpected argument `" + argument + "' provided for -D option in `" + s + "'"; - throw e; + throw new ParseException($"unexpected argument '{argument}' provided for -D option in proxy string '{s}'"); } mode = Reference.Mode.ModeBatchDatagram; break; @@ -329,9 +301,7 @@ public Reference create(string s, string propertyPrefix) { if (argument != null) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "unexpected argument `" + argument + "' provided for -s option in `" + s + "'"; - throw e; + throw new ParseException($"unexpected argument '{argument}' provided for -s option in proxy string '{s}'"); } secure = true; break; @@ -341,17 +311,16 @@ public Reference create(string s, string propertyPrefix) { if (argument == null) { - throw new Ice.ProxyParseException("no argument provided for -e option `" + s + "'"); + throw new ParseException($"no argument provided for -e option in proxy string '{s}'"); } try { encoding = Ice.Util.stringToEncodingVersion(argument); } - catch (Ice.VersionParseException e) + catch (ParseException e) { - throw new Ice.ProxyParseException("invalid encoding version `" + argument + "' in `" + s + - "':\n" + e.str); + throw new ParseException($"invalid encoding version '{argument}' in proxy string '{s}'", e); } break; } @@ -360,26 +329,23 @@ public Reference create(string s, string propertyPrefix) { if (argument == null) { - throw new Ice.ProxyParseException("no argument provided for -p option `" + s + "'"); + throw new ParseException($"no argument provided for -p option in proxy string '{s}'"); } try { protocol = Ice.Util.stringToProtocolVersion(argument); } - catch (Ice.VersionParseException e) + catch (ParseException e) { - throw new Ice.ProxyParseException("invalid protocol version `" + argument + "' in `" + s + - "':\n" + e.str); + throw new ParseException($"invalid protocol version '{argument}' in proxy string '{s}'", e); } break; } default: { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "unknown option `" + option + "' in `" + s + "'"; - throw e; + throw new ParseException($"unknown option '{option}' in proxy string '{s}'"); } } } @@ -457,9 +423,7 @@ public Reference create(string s, string propertyPrefix) if (endpoints.Count == 0) { Debug.Assert(unknownEndpoints.Count > 0); - Ice.EndpointParseException e2 = new Ice.EndpointParseException(); - e2.str = "invalid endpoint `" + unknownEndpoints[0] + "' in `" + s + "'"; - throw e2; + throw new ParseException($"invalid endpoint '{unknownEndpoints[0]}' in '{s}'"); } else if (unknownEndpoints.Count != 0 && _instance.initializationData().properties.getPropertyAsIntWithDefault( @@ -484,18 +448,14 @@ public Reference create(string s, string propertyPrefix) beg = Ice.UtilInternal.StringUtil.findFirstNotOf(s, delim, beg + 1); if (beg == -1) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "missing adapter id in `" + s + "'"; - throw e; + throw new ParseException($"missing adapter ID in proxy string '{s}'"); } string adapterstr = null; end = Ice.UtilInternal.StringUtil.checkQuote(s, beg); if (end == -1) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "mismatched quotes around adapter id in `" + s + "'"; - throw e; + throw new ParseException($"mismatched quotes around adapter ID in proxy string '{s}'"); } else if (end == 0) { @@ -515,9 +475,7 @@ public Reference create(string s, string propertyPrefix) if (end != s.Length && Ice.UtilInternal.StringUtil.findFirstNotOf(s, delim, end) != -1) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "invalid trailing characters after `" + s.Substring(0, end + 1) + "' in `" + s + "'"; - throw e; + throw new ParseException($"invalid characters after adapter ID in proxy string '{s}'"); } try @@ -526,22 +484,16 @@ public Reference create(string s, string propertyPrefix) } catch (ArgumentException argEx) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "invalid adapter id in `" + s + "': " + argEx.Message; - throw e; + throw new ParseException($"invalid adapter ID in proxy string '{s}'", argEx); } if (adapter.Length == 0) { - Ice.ProxyParseException e = new Ice.ProxyParseException(); - e.str = "empty adapter id in `" + s + "'"; - throw e; + throw new ParseException($"empty adapter ID in proxy string '{s}'"); } return create(ident, facet, mode, secure, protocol, encoding, null, adapter, propertyPrefix); } - Ice.ProxyParseException ex = new Ice.ProxyParseException(); - ex.str = "malformed proxy `" + s + "'"; - throw ex; + throw new ParseException($"malformed proxy string '{s}'"); } public Reference create(Ice.Identity ident, Ice.InputStream s) @@ -565,7 +517,7 @@ public Reference create(Ice.Identity ident, Ice.InputStream s) { if (facetPath.Length > 1) { - throw new Ice.ProxyUnmarshalException(); + throw new MarshalException($"Received invalid facet path with {facetPath.Length} elements."); } facet = facetPath[0]; } @@ -577,7 +529,7 @@ public Reference create(Ice.Identity ident, Ice.InputStream s) int mode = s.readByte(); if (mode < 0 || mode > (int)Reference.Mode.ModeLast) { - throw new Ice.ProxyUnmarshalException(); + throw new MarshalException($"Received invalid proxy mode {mode}"); } bool secure = s.readBool(); @@ -831,8 +783,7 @@ private Reference create(Ice.Identity ident, } else { - throw new Ice.EndpointSelectionTypeParseException("illegal value `" + type + - "'; expected `Random' or `Ordered'"); + throw new ParseException($"illegal value '{type}' in property '{property}'; expected 'Random' or 'Ordered'"); } } diff --git a/csharp/src/Ice/Internal/RequestHandlerCache.cs b/csharp/src/Ice/Internal/RequestHandlerCache.cs index 6599f06f94d..97eb71680d7 100644 --- a/csharp/src/Ice/Internal/RequestHandlerCache.cs +++ b/csharp/src/Ice/Internal/RequestHandlerCache.cs @@ -215,9 +215,8 @@ private static int checkRetryAfterException(Ice.LocalException ex, Reference @re // instead), which means there was a problem in this process that will // not change if we try again. // - // The most likely cause for a MarshalException is exceeding the - // maximum message size, which is represented by the subclass - // MemoryLimitException. For example, a client can attempt to send a + // A likely cause for a MarshalException is exceeding the + // maximum message size. For example, a client can attempt to send a // message that exceeds the maximum memory size, or accumulate enough // batch requests without flushing that the maximum size is reached. // @@ -236,11 +235,14 @@ private static int checkRetryAfterException(Ice.LocalException ex, Reference @re // // Don't retry if the communicator is destroyed, object adapter is deactivated, - // or connection is manually closed. + // or connection is closed by the application. // - if (ex is Ice.CommunicatorDestroyedException || - ex is Ice.ObjectAdapterDeactivatedException || - ex is Ice.ConnectionManuallyClosedException) + if (ex is CommunicatorDestroyedException || + ex is ObjectAdapterDeactivatedException || + (ex is ConnectionAbortedException connectionAbortedException && + connectionAbortedException.closedByApplication) || + (ex is ConnectionClosedException connectionClosedException && + connectionClosedException.closedByApplication)) { throw ex; } diff --git a/csharp/src/Ice/Internal/RouterInfo.cs b/csharp/src/Ice/Internal/RouterInfo.cs index a7eccb98215..19ea14012c6 100644 --- a/csharp/src/Ice/Internal/RouterInfo.cs +++ b/csharp/src/Ice/Internal/RouterInfo.cs @@ -104,7 +104,7 @@ public EndpointI[] getServerEndpoints() Ice.ObjectPrx serverProxy = _router.getServerProxy(); if (serverProxy == null) { - throw new Ice.NoEndpointException(); + throw new NoEndpointException("Router::getServerProxy returned a null proxy."); } serverProxy = serverProxy.ice_router(null); // The server proxy cannot be routed. diff --git a/csharp/src/Ice/Internal/ServantManager.cs b/csharp/src/Ice/Internal/ServantManager.cs index 5466a1b44ea..7b000cdd656 100644 --- a/csharp/src/Ice/Internal/ServantManager.cs +++ b/csharp/src/Ice/Internal/ServantManager.cs @@ -85,14 +85,12 @@ internal void addServant(Object servant, Identity ident, string facet) { if (m.ContainsKey(facet)) { - AlreadyRegisteredException ex = new AlreadyRegisteredException(); - ex.id = Ice.Util.identityToString(ident, _instance.toStringMode()); - ex.kindOfObject = "servant"; + string id = Ice.Util.identityToString(ident, _instance.toStringMode()); if (facet.Length > 0) { - ex.id += " -f " + UtilInternal.StringUtil.escapeString(facet, "", _instance.toStringMode()); + id += " -f " + UtilInternal.StringUtil.escapeString(facet, "", _instance.toStringMode()); } - throw ex; + throw new AlreadyRegisteredException("servant", id); } } else @@ -111,10 +109,7 @@ internal void addDefaultServant(Object servant, string category) { if (_defaultServantMap.TryGetValue(category, out Object? obj)) { - AlreadyRegisteredException ex = new AlreadyRegisteredException(); - ex.kindOfObject = "default servant"; - ex.id = category; - throw ex; + throw new AlreadyRegisteredException("default servant", category); } _defaultServantMap[category] = servant; @@ -132,14 +127,12 @@ internal Object removeServant(Identity ident, string facet) Object? obj = null; if (m is null || !m.TryGetValue(facet, out Object? value)) { - NotRegisteredException ex = new NotRegisteredException(); - ex.id = Ice.Util.identityToString(ident, _instance.toStringMode()); - ex.kindOfObject = "servant"; + string id = Ice.Util.identityToString(ident, _instance.toStringMode()); if (facet.Length > 0) { - ex.id += " -f " + UtilInternal.StringUtil.escapeString(facet, "", _instance.toStringMode()); + id += " -f " + UtilInternal.StringUtil.escapeString(facet, "", _instance.toStringMode()); } - throw ex; + throw new NotRegisteredException("servant", id); } obj = value; m.Remove(facet); @@ -158,10 +151,7 @@ internal Object removeDefaultServant(string category) { if (!_defaultServantMap.TryGetValue(category, out Object? obj)) { - NotRegisteredException ex = new NotRegisteredException(); - ex.kindOfObject = "default servant"; - ex.id = category; - throw ex; + throw new NotRegisteredException("default servant", category); } _defaultServantMap.Remove(category); @@ -175,10 +165,7 @@ internal Dictionary removeAllFacets(Identity ident) { if (!_servantMapMap.TryGetValue(ident, out Dictionary? m)) { - NotRegisteredException ex = new NotRegisteredException(); - ex.id = Ice.Util.identityToString(ident, _instance.toStringMode()); - ex.kindOfObject = "servant"; - throw ex; + throw new NotRegisteredException("servant", Ice.Util.identityToString(ident, _instance.toStringMode())); } _servantMapMap.Remove(ident); @@ -246,10 +233,9 @@ internal void addServantLocator(ServantLocator locator, string category) { if (_locatorMap.TryGetValue(category, out ServantLocator? l)) { - AlreadyRegisteredException ex = new AlreadyRegisteredException(); - ex.id = UtilInternal.StringUtil.escapeString(category, "", _instance.toStringMode()); - ex.kindOfObject = "servant locator"; - throw ex; + throw new AlreadyRegisteredException( + "servant locator", + UtilInternal.StringUtil.escapeString(category, "", _instance.toStringMode())); } _locatorMap[category] = locator; @@ -262,10 +248,9 @@ internal ServantLocator removeServantLocator(string category) { if (!_locatorMap.TryGetValue(category, out ServantLocator? l)) { - NotRegisteredException ex = new NotRegisteredException(); - ex.id = UtilInternal.StringUtil.escapeString(category, "", _instance.toStringMode()); - ex.kindOfObject = "servant locator"; - throw ex; + throw new NotRegisteredException( + "servant locator", + UtilInternal.StringUtil.escapeString(category, "", _instance.toStringMode())); } _locatorMap.Remove(category); return l; diff --git a/csharp/src/Ice/Internal/StreamSocket.cs b/csharp/src/Ice/Internal/StreamSocket.cs index b58eb8de31c..12913269f60 100644 --- a/csharp/src/Ice/Internal/StreamSocket.cs +++ b/csharp/src/Ice/Internal/StreamSocket.cs @@ -382,10 +382,10 @@ private int read(ByteBuffer buf) } else if (Network.connectionLost(ex)) { - throw new Ice.ConnectionLostException(ex); + throw new ConnectionLostException(ex); } - throw new Ice.SocketException(ex); + throw new SocketException(ex); } } return read; diff --git a/csharp/src/Ice/Internal/TcpEndpointI.cs b/csharp/src/Ice/Internal/TcpEndpointI.cs index f83f6add3eb..ce586d594a1 100644 --- a/csharp/src/Ice/Internal/TcpEndpointI.cs +++ b/csharp/src/Ice/Internal/TcpEndpointI.cs @@ -219,8 +219,7 @@ protected override bool checkOption(string option, string argument, string endpo { if (argument == null) { - throw new Ice.EndpointParseException("no argument provided for -t option in endpoint " + - endpoint); + throw new ParseException($"no argument provided for -t option in endpoint '{endpoint}'"); } if (argument == "infinite") @@ -234,16 +233,12 @@ protected override bool checkOption(string option, string argument, string endpo _timeout = int.Parse(argument, CultureInfo.InvariantCulture); if (_timeout < 1) { - Ice.EndpointParseException e = new Ice.EndpointParseException(); - e.str = "invalid timeout value `" + argument + "' in endpoint " + endpoint; - throw e; + throw new ParseException($"invalid timeout value '{argument}' in endpoint {endpoint}"); } } catch (System.FormatException ex) { - Ice.EndpointParseException e = new Ice.EndpointParseException(ex); - e.str = "invalid timeout value `" + argument + "' in endpoint " + endpoint; - throw e; + throw new ParseException($"invalid timeout value '{argument}' in endpoint {endpoint}", ex); } } @@ -254,8 +249,7 @@ protected override bool checkOption(string option, string argument, string endpo { if (argument != null) { - throw new Ice.EndpointParseException("unexpected argument `" + argument + - "' provided for -z option in " + endpoint); + throw new ParseException($"unexpected argument '{argument}' provided for -z option in endpoint '{endpoint}'"); } _compress = true; diff --git a/csharp/src/Ice/Internal/UdpEndpointI.cs b/csharp/src/Ice/Internal/UdpEndpointI.cs index 16f67a2962a..3337ec66be7 100644 --- a/csharp/src/Ice/Internal/UdpEndpointI.cs +++ b/csharp/src/Ice/Internal/UdpEndpointI.cs @@ -162,8 +162,7 @@ public override void initWithOptions(List args, bool oaEndpoint) } else { - throw new Ice.EndpointParseException("`--interface *' not valid for proxy endpoint `" + - ToString() + "'"); + throw new ParseException($"'--interface *' not valid for proxy endpoint '{this}'"); } } } @@ -320,9 +319,7 @@ protected override bool checkOption(string option, string argument, string endpo { if (argument != null) { - Ice.EndpointParseException e = new Ice.EndpointParseException(); - e.str = "unexpected argument `" + argument + "' provided for -c option in " + endpoint; - throw e; + throw new ParseException($"unexpected argument '{argument}' provided for -c option in endpoint '{endpoint}'"); } _connect = true; @@ -331,9 +328,7 @@ protected override bool checkOption(string option, string argument, string endpo { if (argument != null) { - Ice.EndpointParseException e = new Ice.EndpointParseException(); - e.str = "unexpected argument `" + argument + "' provided for -z option in " + endpoint; - throw e; + throw new ParseException($"unexpected argument '{argument}' provided for -z option in endpoint '{endpoint}'"); } _compress = true; @@ -342,9 +337,7 @@ protected override bool checkOption(string option, string argument, string endpo { if (argument == null) { - Ice.EndpointParseException e = new Ice.EndpointParseException(); - e.str = "no argument provided for " + option + " option in endpoint " + endpoint; - throw e; + throw new ParseException($"unexpected argument '{argument}' provided for {option} option in endpoint '{endpoint}'"); } try @@ -355,20 +348,16 @@ protected override bool checkOption(string option, string argument, string endpo instance_.logger().warning("deprecated udp endpoint option: " + option); } } - catch (Ice.VersionParseException ex) + catch (ParseException ex) { - Ice.EndpointParseException e = new Ice.EndpointParseException(); - e.str = "invalid version `" + argument + "' in endpoint " + endpoint + ":\n" + ex.str; - throw e; + throw new ParseException($"invalid version '{argument}' in endpoint '{endpoint}'", ex); } } else if (option == "--ttl") { if (argument == null) { - Ice.EndpointParseException e = new Ice.EndpointParseException(); - e.str = "no argument provided for --ttl option in endpoint " + endpoint; - throw e; + throw new ParseException($"no argument provided for --ttl option in endpoint '{endpoint}'"); } try @@ -377,25 +366,19 @@ protected override bool checkOption(string option, string argument, string endpo } catch (FormatException ex) { - Ice.EndpointParseException e = new Ice.EndpointParseException(ex); - e.str = "invalid TTL value `" + argument + "' in endpoint " + endpoint; - throw e; + throw new ParseException($"invalid TTL value '{argument}' in endpoint '{endpoint}'", ex); } if (_mcastTtl < 0) { - Ice.EndpointParseException e = new Ice.EndpointParseException(); - e.str = "TTL value `" + argument + "' out of range in endpoint " + endpoint; - throw e; + throw new ParseException($"TTL value '{argument}' out of range in endpoint '{endpoint}'"); } } else if (option == "--interface") { if (argument == null) { - Ice.EndpointParseException e = new Ice.EndpointParseException(); - e.str = "no argument provided for --interface option in endpoint " + endpoint; - throw e; + throw new ParseException($"no argument provided for --interface option in endpoint '{endpoint}'"); } _mcastInterface = argument; } diff --git a/csharp/src/Ice/Internal/UdpTransceiver.cs b/csharp/src/Ice/Internal/UdpTransceiver.cs index db1804bf615..6096eb32298 100644 --- a/csharp/src/Ice/Internal/UdpTransceiver.cs +++ b/csharp/src/Ice/Internal/UdpTransceiver.cs @@ -250,7 +250,7 @@ public int read(Buffer buf, ref bool hasMoreData) if (Network.connectionLost(e)) { - throw new Ice.ConnectionLostException(); + throw new ConnectionLostException(e); } else { @@ -259,7 +259,7 @@ public int read(Buffer buf, ref bool hasMoreData) } catch (System.Exception e) { - throw new Ice.SyscallException(e); + throw new SyscallException(e); } } diff --git a/csharp/src/Ice/Internal/ValueFactoryManager.cs b/csharp/src/Ice/Internal/ValueFactoryManager.cs index 5baf53ab645..d8c0b2e358d 100644 --- a/csharp/src/Ice/Internal/ValueFactoryManager.cs +++ b/csharp/src/Ice/Internal/ValueFactoryManager.cs @@ -10,10 +10,7 @@ public void add(Ice.ValueFactory factory, string id) { if (_factoryMap.ContainsKey(id)) { - Ice.AlreadyRegisteredException ex = new Ice.AlreadyRegisteredException(); - ex.id = id; - ex.kindOfObject = "value factory"; - throw ex; + throw new AlreadyRegisteredException("value factory", id); } _factoryMap[id] = factory; } diff --git a/csharp/src/Ice/Internal/WSEndpoint.cs b/csharp/src/Ice/Internal/WSEndpoint.cs index 5ddb6f12577..7f2571f1d4c 100644 --- a/csharp/src/Ice/Internal/WSEndpoint.cs +++ b/csharp/src/Ice/Internal/WSEndpoint.cs @@ -309,9 +309,7 @@ protected override bool checkOption(string option, string argument, string endpo { if (argument == null) { - Ice.EndpointParseException e = new Ice.EndpointParseException(); - e.str = "no argument provided for -r option in endpoint " + endpoint + _delegate.options(); - throw e; + throw new ParseException($"no argument provided for -r option in endpoint '{endpoint}{_delegate.options()}'"); } _resource = argument; return true; diff --git a/csharp/src/Ice/Internal/WSTransceiver.cs b/csharp/src/Ice/Internal/WSTransceiver.cs index 74b99d0ba95..d9b42ec2c2d 100644 --- a/csharp/src/Ice/Internal/WSTransceiver.cs +++ b/csharp/src/Ice/Internal/WSTransceiver.cs @@ -127,7 +127,9 @@ public int initialize(Buffer readBuffer, Buffer writeBuffer, ref bool hasMoreDat int oldSize = _readBuffer.b.position(); if (oldSize + 1024 > _instance.messageSizeMax()) { - throw new Ice.MemoryLimitException(); + Ex.throwMemoryLimitException( + requested: oldSize + 1024, + maximum: _instance.messageSizeMax()); } _readBuffer.resize(oldSize + 1024, true); _readBuffer.b.position(oldSize); @@ -273,11 +275,6 @@ public int closing(bool initiator, Ice.LocalException reason) { _closingReason = CLOSURE_PROTOCOL_ERROR; } - else if (reason is Ice.MemoryLimitException) - { - _closingReason = CLOSURE_TOO_BIG; - } - if (_state == StateOpened) { _state = StateClosingRequestPending; @@ -1684,7 +1681,6 @@ private void prepareWriteHeader(byte opCode, int payloadLength) private const int CLOSURE_NORMAL = 1000; private const int CLOSURE_SHUTDOWN = 1001; private const int CLOSURE_PROTOCOL_ERROR = 1002; - private const int CLOSURE_TOO_BIG = 1009; private const string _iceProtocol = "ice.zeroc.com"; private const string _wsUUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; diff --git a/csharp/src/Ice/LocalException.cs b/csharp/src/Ice/LocalException.cs index 6ab7208a707..51ca9de20c2 100644 --- a/csharp/src/Ice/LocalException.cs +++ b/csharp/src/Ice/LocalException.cs @@ -1,2034 +1,32 @@ // Copyright (c) ZeroC, Inc. -namespace Ice; - -/// -/// This exception is raised when a failure occurs during initialization. -/// -public class InitializationException : LocalException -{ - public string reason; - - private void _initDM() - { - this.reason = ""; - } - - public InitializationException() - { - _initDM(); - } - - public InitializationException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string reason) - { - this.reason = reason; - } - - public InitializationException(string reason) - { - _initDM(reason); - } - - public InitializationException(string reason, System.Exception ex) : base(ex) - { - _initDM(reason); - } - - public override string ice_id() - { - return "::Ice::InitializationException"; - } -} - -/// -/// This exception indicates that a failure occurred while initializing a plug-in. -/// -public class PluginInitializationException : LocalException -{ - public string reason; - - private void _initDM() - { - this.reason = ""; - } - - public PluginInitializationException() - { - _initDM(); - } - - public PluginInitializationException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string reason) - { - this.reason = reason; - } - - public PluginInitializationException(string reason) - { - _initDM(reason); - } - - public PluginInitializationException(string reason, System.Exception ex) : base(ex) - { - _initDM(reason); - } - - public override string ice_id() - { - return "::Ice::PluginInitializationException"; - } -} - -/// -/// An attempt was made to register something more than once with the Ice run time. -/// This exception is raised if an -/// attempt is made to register a servant, servant locator, facet, value factory, plug-in, object adapter, object, or -/// user exception factory more than once for the same ID. -/// -public class AlreadyRegisteredException : LocalException -{ - public string kindOfObject; - public string id; - - private void _initDM() - { - this.kindOfObject = ""; - this.id = ""; - } - - public AlreadyRegisteredException() - { - _initDM(); - } - - public AlreadyRegisteredException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string kindOfObject, string id) - { - this.kindOfObject = kindOfObject; - this.id = id; - } - - public AlreadyRegisteredException(string kindOfObject, string id) - { - _initDM(kindOfObject, id); - } - - [System.CodeDom.Compiler.GeneratedCodeAttribute("slice2cs", "3.7.10")] - public AlreadyRegisteredException(string kindOfObject, string id, System.Exception ex) : base(ex) - { - _initDM(kindOfObject, id); - } - - public override string ice_id() - { - return "::Ice::AlreadyRegisteredException"; - } -} - -/// -/// An attempt was made to find or deregister something that is not registered with the Ice run time or Ice locator. -/// This exception is raised if an attempt is made to remove a servant, servant locator, facet, value factory, plug-in, -/// object adapter, object, or user exception factory that is not currently registered. It's also raised if the Ice -/// locator can't find an object or object adapter when resolving an indirect proxy or when an object adapter is -/// activated. -/// -public class NotRegisteredException : LocalException -{ - public string kindOfObject; - public string id; - - private void _initDM() - { - this.kindOfObject = ""; - this.id = ""; - } - - public NotRegisteredException() - { - _initDM(); - } - - public NotRegisteredException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string kindOfObject, string id) - { - this.kindOfObject = kindOfObject; - this.id = id; - } - - public NotRegisteredException(string kindOfObject, string id) - { - _initDM(kindOfObject, id); - } - - public NotRegisteredException(string kindOfObject, string id, System.Exception ex) : base(ex) - { - _initDM(kindOfObject, id); - } - public override string ice_id() - { - return "::Ice::NotRegisteredException"; - } -} - -/// -/// The operation can only be invoked with a twoway request. -/// This exception is raised if an attempt is made to invoke -/// an operation with ice_oneway, ice_batchOneway, ice_datagram, or -/// ice_batchDatagram and the operation has a return value, out-parameters, or an exception specification. -/// -public class TwowayOnlyException : LocalException -{ - public string operation; - - private void _initDM() - { - this.operation = ""; - } - - public TwowayOnlyException() - { - _initDM(); - } - - public TwowayOnlyException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string operation) - { - this.operation = operation; - } - - public TwowayOnlyException(string operation) - { - _initDM(operation); - } - - public TwowayOnlyException(string operation, System.Exception ex) : base(ex) - { - _initDM(operation); - } - - public override string ice_id() - { - return "::Ice::TwowayOnlyException"; - } -} - -/// -/// This exception is raised if an operation call on a server raises an unknown exception. -/// For example, for C++, this -/// exception is raised if the server throws a C++ exception that is not directly or indirectly derived from -/// Ice::LocalException or Ice::UserException. -/// -public class UnknownException : LocalException -{ - public string unknown; - private void _initDM() - { - this.unknown = ""; - } - - public UnknownException() - { - _initDM(); - } - - public UnknownException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string unknown) - { - this.unknown = unknown; - } - - public UnknownException(string unknown) - { - _initDM(unknown); - } - - public UnknownException(string unknown, System.Exception ex) : base(ex) - { - _initDM(unknown); - } - - public override string ice_id() - { - return "::Ice::UnknownException"; - } -} - -/// -/// This exception is raised if an operation call on a server raises a local exception. -/// Because local exceptions are -/// not transmitted by the Ice protocol, the client receives all local exceptions raised by the server as -/// UnknownLocalException. The only exception to this rule are all exceptions derived from -/// RequestFailedException, which are transmitted by the Ice protocol even though they are declared -/// local. -/// -public class UnknownLocalException : UnknownException -{ - public UnknownLocalException() - { - } - - public UnknownLocalException(System.Exception ex) : base(ex) - { - } - - public UnknownLocalException(string unknown) : base(unknown) - { - } - - public UnknownLocalException(string unknown, System.Exception ex) : base(unknown, ex) - { - } - - public override string ice_id() - { - return "::Ice::UnknownLocalException"; - } -} - -/// -/// An operation raised an incorrect user exception. -/// This exception is raised if an operation raises a user exception -/// that is not declared in the exception's throws clause. Such undeclared exceptions are not transmitted -/// from the server to the client by the Ice protocol, but instead the client just gets an UnknownUserException. -/// This is necessary in order to not violate the contract established by an operation's signature: Only local -/// exceptions and user exceptions declared in the throws clause can be raised. -/// -public class UnknownUserException : UnknownException -{ - public UnknownUserException() - { - } - - public UnknownUserException(System.Exception ex) : base(ex) - { - } - - public UnknownUserException(string unknown) : base(unknown) - { - } - - public UnknownUserException(string unknown, System.Exception ex) : base(unknown, ex) - { - } - - public override string ice_id() - { - return "::Ice::UnknownUserException"; - } -} - -/// -/// This exception is raised if the Communicator has been destroyed. -/// -public class CommunicatorDestroyedException : LocalException -{ - public CommunicatorDestroyedException() - { - } - - public CommunicatorDestroyedException(System.Exception ex) : base(ex) - { - } - - public override string ice_id() - { - return "::Ice::CommunicatorDestroyedException"; - } -} - -/// -/// This exception is raised if an attempt is made to use a deactivated ObjectAdapter. -/// -public class ObjectAdapterDeactivatedException : LocalException -{ - public string name; - - private void _initDM() - { - this.name = ""; - } - - public ObjectAdapterDeactivatedException() - { - _initDM(); - } - - public ObjectAdapterDeactivatedException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string name) - { - this.name = name; - } - - public ObjectAdapterDeactivatedException(string name) - { - _initDM(name); - } - - public ObjectAdapterDeactivatedException(string name, System.Exception ex) : base(ex) - { - _initDM(name); - } - - public override string ice_id() - { - return "::Ice::ObjectAdapterDeactivatedException"; - } -} - -/// -/// This exception is raised if an ObjectAdapter cannot be activated. -/// This happens if the Locator -/// detects another active ObjectAdapter with the same adapter id. -/// -public class ObjectAdapterIdInUseException : LocalException -{ - public string id; - - private void _initDM() - { - this.id = ""; - } - - public ObjectAdapterIdInUseException() - { - _initDM(); - } - - public ObjectAdapterIdInUseException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string id) - { - this.id = id; - } - - public ObjectAdapterIdInUseException(string id) - { - _initDM(id); - } - - public ObjectAdapterIdInUseException(string id, System.Exception ex) : base(ex) - { - _initDM(id); - } - - public override string ice_id() - { - return "::Ice::ObjectAdapterIdInUseException"; - } -} - -/// -/// This exception is raised if no suitable endpoint is available. -/// -public class NoEndpointException : LocalException -{ - public string proxy; - - private void _initDM() - { - this.proxy = ""; - } - - public NoEndpointException() - { - _initDM(); - } - - public NoEndpointException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string proxy) - { - this.proxy = proxy; - } - - public NoEndpointException(string proxy) - { - _initDM(proxy); - } - - public NoEndpointException(string proxy, System.Exception ex) : base(ex) - { - _initDM(proxy); - } - - public override string ice_id() - { - return "::Ice::NoEndpointException"; - } -} - -/// -/// This exception is raised if there was an error while parsing an endpoint. -/// -public class EndpointParseException : LocalException -{ - public string str; - - private void _initDM() - { - this.str = ""; - } - - public EndpointParseException() - { - _initDM(); - } - - public EndpointParseException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string str) - { - this.str = str; - } - - public EndpointParseException(string str) - { - _initDM(str); - } - - public EndpointParseException(string str, System.Exception ex) : base(ex) - { - _initDM(str); - } - - public override string ice_id() - { - return "::Ice::EndpointParseException"; - } -} - -/// -/// This exception is raised if there was an error while parsing an endpoint selection type. -/// -public class EndpointSelectionTypeParseException : LocalException -{ - public string str; - - private void _initDM() - { - this.str = ""; - } - - public EndpointSelectionTypeParseException() - { - _initDM(); - } - - public EndpointSelectionTypeParseException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string str) - { - this.str = str; - } - - public EndpointSelectionTypeParseException(string str) - { - _initDM(str); - } - - public EndpointSelectionTypeParseException(string str, System.Exception ex) : base(ex) - { - _initDM(str); - } - - public override string ice_id() - { - return "::Ice::EndpointSelectionTypeParseException"; - } -} - -/// -/// This exception is raised if there was an error while parsing a version. -/// -public class VersionParseException : LocalException -{ - public string str; - - private void _initDM() - { - this.str = ""; - } - - public VersionParseException() - { - _initDM(); - } - - public VersionParseException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string str) - { - this.str = str; - } - - public VersionParseException(string str) - { - _initDM(str); - } - - public VersionParseException(string str, System.Exception ex) : base(ex) - { - _initDM(str); - } - - public override string ice_id() - { - return "::Ice::VersionParseException"; - } -} - -/// -/// This exception is raised if there was an error while parsing a stringified identity. -/// -public class IdentityParseException : LocalException -{ - public string str; - - private void _initDM() - { - this.str = ""; - } - - public IdentityParseException() - { - _initDM(); - } - - public IdentityParseException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string str) - { - this.str = str; - } - - public IdentityParseException(string str) - { - _initDM(str); - } - - public IdentityParseException(string str, System.Exception ex) : base(ex) - { - _initDM(str); - } - - public override string ice_id() - { - return "::Ice::IdentityParseException"; - } -} - -/// -/// This exception is raised if there was an error while parsing a stringified proxy. -/// -public class ProxyParseException : LocalException -{ - public string str; - - private void _initDM() - { - this.str = ""; - } - - public ProxyParseException() - { - _initDM(); - } - - public ProxyParseException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string str) - { - this.str = str; - } - - public ProxyParseException(string str) - { - _initDM(str); - } - - public ProxyParseException(string str, System.Exception ex) : base(ex) - { - _initDM(str); - } - - public override string ice_id() - { - return "::Ice::ProxyParseException"; - } -} - -/// -/// This exception is raised if an illegal identity is encountered. -/// -public class IllegalIdentityException : LocalException -{ - public Identity id; - - private void _initDM() - { - this.id = new Identity(); - } - - public IllegalIdentityException() - { - _initDM(); - } - - public IllegalIdentityException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(Identity id) - { - this.id = id; - } - - public IllegalIdentityException(Identity id) - { - _initDM(id); - } - - public IllegalIdentityException(Identity id, System.Exception ex) : base(ex) - { - _initDM(id); - } - - public override string ice_id() - { - return "::Ice::IllegalIdentityException"; - } -} - -/// -/// This exception is raised to reject an illegal servant (typically a null servant). -/// -public class IllegalServantException : LocalException -{ - public string reason; - - private void _initDM() - { - this.reason = ""; - } - - public IllegalServantException() - { - _initDM(); - } - - public IllegalServantException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string reason) - { - this.reason = reason; - } - - public IllegalServantException(string reason) - { - _initDM(reason); - } - - public IllegalServantException(string reason, System.Exception ex) : base(ex) - { - _initDM(reason); - } - - public override string ice_id() - { - return "::Ice::IllegalServantException"; - } -} - -/// -/// This exception is raised if a request failed. -/// This exception, and all exceptions derived from -/// RequestFailedException, are transmitted by the Ice protocol, even though they are declared -/// local. -/// -public class RequestFailedException : LocalException -{ - public Identity id; - public string facet; - public string operation; - - private void _initDM() - { - this.id = new Identity(); - this.facet = ""; - this.operation = ""; - } - - public RequestFailedException() - { - _initDM(); - } - - public RequestFailedException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(Identity id, string facet, string operation) - { - this.id = id; - this.facet = facet; - this.operation = operation; - } - - public RequestFailedException(Identity id, string facet, string operation) - { - _initDM(id, facet, operation); - } - - public RequestFailedException(Identity id, string facet, string operation, System.Exception ex) : base(ex) - { - _initDM(id, facet, operation); - } - - public override string ice_id() - { - return "::Ice::RequestFailedException"; - } -} - -/// -/// This exception is raised if an object does not exist on the server, that is, if no facets with the given identity -/// exist. -/// -public class ObjectNotExistException : RequestFailedException -{ - public ObjectNotExistException() - { - } - - public ObjectNotExistException(System.Exception ex) : base(ex) - { - } - - public ObjectNotExistException(Identity id, string facet, string operation) : base(id, facet, operation) - { - } - - public ObjectNotExistException(Identity id, string facet, string operation, System.Exception ex) - : base(id, facet, operation, ex) - { - } - - public override string ice_id() - { - return "::Ice::ObjectNotExistException"; - } -} - -/// -/// This exception is raised if no facet with the given name exists, but at least one facet with the given identity -/// exists. -/// -public class FacetNotExistException : RequestFailedException -{ - public FacetNotExistException() - { - } - - public FacetNotExistException(System.Exception ex) : base(ex) - { - } - - public FacetNotExistException(Identity id, string facet, string operation) : base(id, facet, operation) - { - } - - public FacetNotExistException(Identity id, string facet, string operation, System.Exception ex) - : base(id, facet, operation, ex) - { - } - - public override string ice_id() - { - return "::Ice::FacetNotExistException"; - } -} - -/// -/// This exception is raised if an operation for a given object does not exist on the server. -/// Typically this is caused -/// by either the client or the server using an outdated Slice specification. -/// -public class OperationNotExistException : RequestFailedException -{ - public OperationNotExistException() - { - } - - public OperationNotExistException(System.Exception ex) : base(ex) - { - } - - public OperationNotExistException(Identity id, string facet, string operation) : base(id, facet, operation) - { - } - - public OperationNotExistException(Identity id, string facet, string operation, System.Exception ex) - : base(id, facet, operation, ex) - { - } - - public override string ice_id() - { - return "::Ice::OperationNotExistException"; - } -} - -/// -/// This exception is raised if a system error occurred in the server or client process. -/// There are many possible causes -/// for such a system exception. For details on the cause, SyscallException.error should be inspected. -/// -public class SyscallException : LocalException -{ - public int error; - - private void _initDM() - { - this.error = 0; - } - - public SyscallException() - { - _initDM(); - } - - public SyscallException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(int error) - { - this.error = error; - } - - public SyscallException(int error) - { - _initDM(error); - } - - public SyscallException(int error, System.Exception ex) : base(ex) - { - _initDM(error); - } - - public override string ice_id() - { - return "::Ice::SyscallException"; - } -} - -/// -/// This exception indicates socket errors. -/// -public class SocketException : SyscallException -{ - public SocketException() - { - } - - public SocketException(System.Exception ex) : base(ex) - { - } - - public SocketException(int error) : base(error) - { - } - - public SocketException(int error, System.Exception ex) : base(error, ex) - { - } - - public override string ice_id() - { - return "::Ice::SocketException"; - } -} - -/// This exception indicates file errors. -public class FileException : SyscallException -{ - public string path; - - private void _initDM() - { - this.path = ""; - } - - public FileException() - { - _initDM(); - } - - public FileException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string path) - { - this.path = path; - } - - public FileException(int error, string path) : base(error) - { - _initDM(path); - } - - public FileException(int error, string path, System.Exception ex) : base(error, ex) - { - _initDM(path); - } - - public override string ice_id() - { - return "::Ice::FileException"; - } -} - -/// -/// This exception indicates connection failures. -/// -public class ConnectFailedException : SocketException -{ - public ConnectFailedException() - { - } - - public ConnectFailedException(System.Exception ex) : base(ex) - { - } - - public ConnectFailedException(int error) : base(error) - { - } - - public ConnectFailedException(int error, System.Exception ex) : base(error, ex) - { - } - - public override string ice_id() - { - return "::Ice::ConnectFailedException"; - } -} - -/// -/// This exception indicates a connection failure for which the server host actively refuses a connection. -/// -public class ConnectionRefusedException : ConnectFailedException -{ - public ConnectionRefusedException() - { - } - - public ConnectionRefusedException(System.Exception ex) : base(ex) - { - } - - public ConnectionRefusedException(int error) : base(error) - { - } - - public ConnectionRefusedException(int error, System.Exception ex) : base(error, ex) - { - } - - public override string ice_id() - { - return "::Ice::ConnectionRefusedException"; - } -} - -/// -/// This exception indicates a lost connection. -/// -public class ConnectionLostException : SocketException -{ - public ConnectionLostException() - { - } - - public ConnectionLostException(System.Exception ex) : base(ex) - { - } - - public ConnectionLostException(int error) : base(error) - { - } - - public ConnectionLostException(int error, System.Exception ex) : base(error, ex) - { - } - - public override string ice_id() - { - return "::Ice::ConnectionLostException"; - } -} - -/// -/// This exception indicates a DNS problem. -/// For details on the cause, DNSException.error should be inspected. -/// -public class DNSException : LocalException -{ - public int error; - public string host; - - private void _initDM() - { - this.error = 0; - this.host = ""; - } - - public DNSException() - { - _initDM(); - } - - public DNSException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(int error, string host) - { - this.error = error; - this.host = host; - } - - public DNSException(int error, string host) - { - _initDM(error, host); - } - - public DNSException(int error, string host, System.Exception ex) : base(ex) - { - _initDM(error, host); - } - - public override string ice_id() - { - return "::Ice::DNSException"; - } -} - -/// -/// This exception indicates that a connection was closed gracefully. -/// -public class ConnectionClosedException : LocalException -{ - public ConnectionClosedException() - { - } - - public override string ice_id() => "::Ice::ConnectionClosedException"; -} - -/// -/// This exception indicates that a connection was aborted by the idle check. -/// -public class ConnectionIdleException : LocalException -{ - public ConnectionIdleException() - { - } - - public override string ice_id() => "::Ice::ConnectionIdleException"; -} - -/// This exception indicates a timeout condition. -public class TimeoutException : LocalException -{ - public TimeoutException() - { - } - - public TimeoutException(System.Exception ex) : base(ex) - { - } - - public override string ice_id() - { - return "::Ice::TimeoutException"; - } -} - -/// -/// This exception indicates a connection establishment timeout condition. -/// -public class ConnectTimeoutException : TimeoutException -{ - public ConnectTimeoutException() - { - } - - public ConnectTimeoutException(System.Exception ex) : base(ex) - { - } - - public override string ice_id() - { - return "::Ice::ConnectTimeoutException"; - } -} - -/// This exception indicates a connection closure timeout condition. -public class CloseTimeoutException : TimeoutException -{ - public CloseTimeoutException() - { - } - - public CloseTimeoutException(System.Exception ex) : base(ex) - { - } - - public override string ice_id() - { - return "::Ice::CloseTimeoutException"; - } -} - -/// -/// This exception indicates that an invocation failed because it timed out. -/// -public class InvocationTimeoutException : TimeoutException -{ - public InvocationTimeoutException() - { - } - - public InvocationTimeoutException(System.Exception ex) : base(ex) - { - } - - public override string ice_id() - { - return "::Ice::InvocationTimeoutException"; - } -} - -/// -/// This exception indicates that an asynchronous invocation failed because it was canceled explicitly by the user. -/// -public class InvocationCanceledException : LocalException -{ - public InvocationCanceledException() - { - } - - public InvocationCanceledException(System.Exception ex) : base(ex) - { - } - - public override string ice_id() - { - return "::Ice::InvocationCanceledException"; - } -} - -/// -/// A generic exception base for all kinds of protocol error conditions. -/// -public class ProtocolException : LocalException -{ - public string reason; - - private void _initDM() - { - this.reason = ""; - } - - public ProtocolException() - { - _initDM(); - } - - public ProtocolException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string reason) - { - this.reason = reason; - } - - public ProtocolException(string reason) - { - _initDM(reason); - } - - public ProtocolException(string reason, System.Exception ex) : base(ex) - { - _initDM(reason); - } - - public override string ice_id() - { - return "::Ice::ProtocolException"; - } -} - -/// -/// This exception indicates that a message did not start with the expected magic number ('I', 'c', 'e', 'P'). -/// -public class BadMagicException : ProtocolException -{ - public byte[] badMagic; - - public BadMagicException() - { - } - - public BadMagicException(System.Exception ex) : base(ex) - { - } - - private void _initDM(byte[] badMagic) - { - this.badMagic = badMagic; - } - - public BadMagicException(string reason, byte[] badMagic) : base(reason) - { - _initDM(badMagic); - } - - public BadMagicException(string reason, byte[] badMagic, System.Exception ex) : base(reason, ex) - { - _initDM(badMagic); - } - - public override string ice_id() - { - return "::Ice::BadMagicException"; - } -} - -/// -/// This exception indicates an unsupported protocol version. -/// -public class UnsupportedProtocolException : ProtocolException -{ - public ProtocolVersion bad; - public ProtocolVersion supported; - - private void _initDM() - { - this.bad = new ProtocolVersion(); - this.supported = new ProtocolVersion(); - } - - public UnsupportedProtocolException() - { - _initDM(); - } - - public UnsupportedProtocolException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(ProtocolVersion bad, ProtocolVersion supported) - { - this.bad = bad; - this.supported = supported; - } - - public UnsupportedProtocolException(string reason, ProtocolVersion bad, ProtocolVersion supported) : base(reason) - { - _initDM(bad, supported); - } - - public UnsupportedProtocolException(string reason, ProtocolVersion bad, ProtocolVersion supported, System.Exception ex) : base(reason, ex) - { - _initDM(bad, supported); - } - - public override string ice_id() - { - return "::Ice::UnsupportedProtocolException"; - } -} - -/// -/// This exception indicates an unsupported data encoding version. -/// -public class UnsupportedEncodingException : ProtocolException -{ - public EncodingVersion bad; - public EncodingVersion supported; - - private void _initDM() - { - this.bad = new EncodingVersion(); - this.supported = new EncodingVersion(); - } - - public UnsupportedEncodingException() - { - _initDM(); - } - - public UnsupportedEncodingException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(EncodingVersion bad, EncodingVersion supported) - { - this.bad = bad; - this.supported = supported; - } - - public UnsupportedEncodingException(string reason, EncodingVersion bad, EncodingVersion supported) : base(reason) - { - _initDM(bad, supported); - } - - public UnsupportedEncodingException(string reason, EncodingVersion bad, EncodingVersion supported, System.Exception ex) : base(reason, ex) - { - _initDM(bad, supported); - } - public override string ice_id() - { - return "::Ice::UnsupportedEncodingException"; - } -} - -/// -/// This exception indicates that an unknown protocol message has been received. -/// -public class UnknownMessageException : ProtocolException -{ - public UnknownMessageException() - { - } - - public UnknownMessageException(System.Exception ex) : base(ex) - { - } - - public UnknownMessageException(string reason) : base(reason) - { - } - - public UnknownMessageException(string reason, System.Exception ex) : base(reason, ex) - { - } - - public override string ice_id() - { - return "::Ice::UnknownMessageException"; - } -} - -/// -/// This exception is raised if a message is received over a connection that is not yet validated. -/// -public class ConnectionNotValidatedException : ProtocolException -{ - public ConnectionNotValidatedException() - { - } - - public ConnectionNotValidatedException(System.Exception ex) : base(ex) - { - } - - public ConnectionNotValidatedException(string reason) : base(reason) - { - } - - public ConnectionNotValidatedException(string reason, System.Exception ex) : base(reason, ex) - { - } - - public override string ice_id() - { - return "::Ice::ConnectionNotValidatedException"; - } -} - -/// -/// This exception indicates that an unknown reply status has been received. -/// -public class UnknownReplyStatusException : ProtocolException -{ - public UnknownReplyStatusException() - { - } - - public UnknownReplyStatusException(System.Exception ex) : base(ex) - { - } - - public UnknownReplyStatusException(string reason) : base(reason) - { - } - - public UnknownReplyStatusException(string reason, System.Exception ex) : base(reason, ex) - { - } - - public override string ice_id() - { - return "::Ice::UnknownReplyStatusException"; - } -} - -/// -/// This exception indicates that the connection has been gracefully shut down by the server. -/// The operation call that -/// caused this exception has not been executed by the server. In most cases you will not get this exception, because -/// the client will automatically retry the operation call in case the server shut down the connection. However, if -/// upon retry the server shuts down the connection again, and the retry limit has been reached, then this exception is -/// propagated to the application code. -/// -public class CloseConnectionException : ProtocolException -{ - public CloseConnectionException() - { - } - - public CloseConnectionException(System.Exception ex) : base(ex) - { - } - - public CloseConnectionException(string reason) : base(reason) - { - } - - public CloseConnectionException(string reason, System.Exception ex) : base(reason, ex) - { - } - - public override string ice_id() - { - return "::Ice::CloseConnectionException"; - } -} - -/// -/// This exception is raised by an operation call if the application closes the connection locally using -/// Connection.close. -/// -public class ConnectionManuallyClosedException : LocalException -{ - public bool graceful; - - private void _initDM() - { - } - - public ConnectionManuallyClosedException() - { - _initDM(); - } - - public ConnectionManuallyClosedException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(bool graceful) - { - this.graceful = graceful; - } - - public ConnectionManuallyClosedException(bool graceful) - { - _initDM(graceful); - } - - public ConnectionManuallyClosedException(bool graceful, System.Exception ex) : base(ex) - { - _initDM(graceful); - } - - public override string ice_id() - { - return "::Ice::ConnectionManuallyClosedException"; - } -} - -/// -/// This exception indicates that a message size is less than the minimum required size. -/// -public class IllegalMessageSizeException : ProtocolException -{ - public IllegalMessageSizeException() - { - } - - public IllegalMessageSizeException(System.Exception ex) : base(ex) - { - } - - public IllegalMessageSizeException(string reason) : base(reason) - { - } - - public IllegalMessageSizeException(string reason, System.Exception ex) : base(reason, ex) - { - } - - public override string ice_id() - { - return "::Ice::IllegalMessageSizeException"; - } -} - -/// -/// This exception indicates a problem with compressing or uncompressing data. -/// -public class CompressionException : ProtocolException -{ - public CompressionException() - { - } - - public CompressionException(System.Exception ex) : base(ex) - { - } - - public CompressionException(string reason) : base(reason) - { - } - - public CompressionException(string reason, System.Exception ex) : base(reason, ex) - { - } - - public override string ice_id() - { - return "::Ice::CompressionException"; - } -} - -/// -/// A datagram exceeds the configured size. -/// This exception is raised if a datagram exceeds the configured send or -/// receive buffer size, or exceeds the maximum payload size of a UDP packet (65507 bytes). -/// -public class DatagramLimitException : ProtocolException -{ - public DatagramLimitException() - { - } - - public DatagramLimitException(System.Exception ex) : base(ex) - { - } - - public DatagramLimitException(string reason) : base(reason) - { - } - - public DatagramLimitException(string reason, System.Exception ex) : base(reason, ex) - { - } - public override string ice_id() - { - return "::Ice::DatagramLimitException"; - } -} - -/// -/// This exception is raised for errors during marshaling or unmarshaling data. -/// -public class MarshalException : ProtocolException -{ - public MarshalException() - { - } - - public MarshalException(System.Exception ex) : base(ex) - { - } - - public MarshalException(string reason) : base(reason) - { - } - - public MarshalException(string reason, System.Exception ex) : base(reason, ex) - { - } - - public override string ice_id() - { - return "::Ice::MarshalException"; - } -} - -/// -/// This exception is raised if inconsistent data is received while unmarshaling a proxy. -/// -public class ProxyUnmarshalException : MarshalException -{ - public ProxyUnmarshalException() - { - } - - public ProxyUnmarshalException(System.Exception ex) : base(ex) - { - } - - public ProxyUnmarshalException(string reason) : base(reason) - { - } - - public ProxyUnmarshalException(string reason, System.Exception ex) : base(reason, ex) - { - } - - public override string ice_id() - { - return "::Ice::ProxyUnmarshalException"; - } -} - -/// -/// This exception is raised if an out-of-bounds condition occurs during unmarshaling. -/// -public class UnmarshalOutOfBoundsException : MarshalException -{ - public UnmarshalOutOfBoundsException() - { - } - - public UnmarshalOutOfBoundsException(System.Exception ex) : base(ex) - { - } - - public UnmarshalOutOfBoundsException(string reason) : base(reason) - { - } - - public UnmarshalOutOfBoundsException(string reason, System.Exception ex) : base(reason, ex) - { - } - - public override string ice_id() - { - return "::Ice::UnmarshalOutOfBoundsException"; - } -} - -/// -/// This exception is raised if no suitable value factory was found during unmarshaling of a Slice class instance. -/// -public class NoValueFactoryException : MarshalException -{ - public string type; - - private void _initDM() - { - this.type = ""; - } - - public NoValueFactoryException() - { - _initDM(); - } - - public NoValueFactoryException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string type) - { - this.type = type; - } +#nullable enable - public NoValueFactoryException(string reason, string type) : base(reason) - { - _initDM(type); - } - - public NoValueFactoryException(string reason, string type, System.Exception ex) : base(reason, ex) - { - _initDM(type); - } - - public override string ice_id() - { - return "::Ice::NoValueFactoryException"; - } -} - -/// -/// This exception is raised if the type of an unmarshaled Slice class instance does not match its expected type. -/// This -/// can happen if client and server are compiled with mismatched Slice definitions or if a class of the wrong type is -/// passed as a parameter or return value using dynamic invocation. This exception can also be raised if IceStorm is -/// used to send Slice class instances and an operation is subscribed to the wrong topic. -/// -public class UnexpectedObjectException : MarshalException -{ - public string type; - public string expectedType; - - private void _initDM() - { - this.type = ""; - this.expectedType = ""; - } - - public UnexpectedObjectException() - { - _initDM(); - } - - public UnexpectedObjectException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string type, string expectedType) - { - this.type = type; - this.expectedType = expectedType; - } - - public UnexpectedObjectException(string reason, string type, string expectedType) : base(reason) - { - _initDM(type, expectedType); - } - - public UnexpectedObjectException(string reason, string type, string expectedType, System.Exception ex) : base(reason, ex) - { - _initDM(type, expectedType); - } - - public override string ice_id() - { - return "::Ice::UnexpectedObjectException"; - } -} - -/// -/// This exception is raised when Ice receives a request or reply message whose size exceeds the limit specified by the -/// Ice.MessageSizeMax property. -/// -public class MemoryLimitException : MarshalException -{ - public MemoryLimitException() - { - } - - public MemoryLimitException(System.Exception ex) : base(ex) - { - } - - public MemoryLimitException(string reason) : base(reason) - { - } - - public MemoryLimitException(string reason, System.Exception ex) : base(reason, ex) - { - } - - public override string ice_id() - { - return "::Ice::MemoryLimitException"; - } -} - -/// -/// This exception indicates a malformed data encapsulation. -/// -public class EncapsulationException : MarshalException -{ - public EncapsulationException() - { - } - - public EncapsulationException(System.Exception ex) : base(ex) - { - } - - public EncapsulationException(string reason) : base(reason) - { - } - - public EncapsulationException(string reason, System.Exception ex) : base(reason, ex) - { - } - - public override string ice_id() - { - return "::Ice::EncapsulationException"; - } -} - -/// -/// This exception is raised if an unsupported feature is used. -/// The unsupported feature string contains the name of the -/// unsupported feature. -/// -public class FeatureNotSupportedException : LocalException -{ - public string unsupportedFeature; - - private void _initDM() - { - this.unsupportedFeature = ""; - } - - public FeatureNotSupportedException() - { - _initDM(); - } - - public FeatureNotSupportedException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string unsupportedFeature) - { - this.unsupportedFeature = unsupportedFeature; - } - - public FeatureNotSupportedException(string unsupportedFeature) - { - _initDM(unsupportedFeature); - } - - public FeatureNotSupportedException(string unsupportedFeature, System.Exception ex) : base(ex) - { - _initDM(unsupportedFeature); - } - - public override string ice_id() - { - return "::Ice::FeatureNotSupportedException"; - } -} - -/// -/// This exception indicates a failure in a security subsystem, such as the IceSSL plug-in. -/// -public class SecurityException : LocalException -{ - public string reason; - - private void _initDM() - { - this.reason = ""; - } - - public SecurityException() - { - _initDM(); - } - - public SecurityException(System.Exception ex) : base(ex) - { - _initDM(); - } - - private void _initDM(string reason) - { - this.reason = reason; - } - - public SecurityException(string reason) - { - _initDM(reason); - } - - public SecurityException(string reason, System.Exception ex) : base(ex) - { - _initDM(reason); - } - - public override string ice_id() - { - return "::Ice::SecurityException"; - } -} +namespace Ice; /// -/// This exception indicates that an attempt has been made to change the connection properties of a fixed proxy. +/// Base class for Ice run-time exceptions. /// -public class FixedProxyException : LocalException +public class LocalException : Ice.Exception { - public FixedProxyException() + /// + /// Constructs a LocalException. + /// + /// The exception message. + /// The inner exception. + public LocalException(string? message = null, System.Exception? innerException = null) + : base(message, innerException) { } - public FixedProxyException(System.Exception ex) : base(ex) + /// + /// Constructs a LocalException. + /// + /// The inner exception. + public LocalException(System.Exception innerException) + : this(message: null, innerException) { } - public override string ice_id() - { - return "::Ice::FixedProxyException"; - } + public override string ice_id() => "::Ice::LocalException"; } diff --git a/csharp/src/Ice/LocalExceptions.cs b/csharp/src/Ice/LocalExceptions.cs new file mode 100644 index 00000000000..f857134447c --- /dev/null +++ b/csharp/src/Ice/LocalExceptions.cs @@ -0,0 +1,598 @@ +// Copyright (c) ZeroC, Inc. + +#nullable enable + +namespace Ice; + +// This file contains all the exception classes derived from LocalException defined in the Ice assembly. + +// +// The 6 (7 with the RequestFailedException base class) special local exceptions that can be marshaled in an Ice reply +// message. Other local exceptions can't be marshaled. +// + +/// +/// The base exception for the 3 NotExist exceptions. +/// +public class RequestFailedException : LocalException +{ + public Identity id { get; } + public string facet { get; } + public string operation { get; } + + protected RequestFailedException(string typeName, Identity id, string facet, string operation) + : base(createMessage(typeName, id, facet, operation)) + { + this.id = id; + this.facet = facet; + this.operation = operation; + } + + protected RequestFailedException() + { + this.id = new Identity(); + this.facet = ""; + this.operation = ""; + } + + internal static string createMessage(string typeName, Identity id, string facet, string operation) => + $"Dispatch failed with {typeName} {{ id = '{Util.identityToString(id)}', facet = '{facet}', operation = '{operation}' }}"; +} + +/// +/// The dispatch could not find a servant for the identity carried by the request. +/// +public sealed class ObjectNotExistException : RequestFailedException +{ + public ObjectNotExistException() + { + } + + public ObjectNotExistException(Identity id, string facet, string operation) + : base(nameof(ObjectNotExistException), id, facet, operation) + { + } + + public override string ice_id() => "::Ice::ObjectNotExistException"; +} + +/// +/// The dispatch could not find a servant for the identity + facet carried by the request. +/// +public sealed class FacetNotExistException : RequestFailedException +{ + public FacetNotExistException() + { + } + + public FacetNotExistException(Identity id, string facet, string operation) + : base(nameof(FacetNotExistException), id, facet, operation) + { + } + + public override string ice_id() => "::Ice::FacetNotExistException"; +} + +/// +/// The dispatch could not find the operation carried by the request on the target servant. This is typically due +/// to a mismatch in the Slice definitions, such as the client using Slice definitions newer than the server's. +/// +public sealed class OperationNotExistException : RequestFailedException +{ + public OperationNotExistException() + { + } + + public OperationNotExistException(Identity id, string facet, string operation) + : base(nameof(OperationNotExistException), id, facet, operation) + { + } + + public override string ice_id() => "::Ice::OperationNotExistException"; +} + +/// +/// The dispatch failed with an exception that is not a or a . +/// +public class UnknownException : LocalException +{ + public string unknown => Message; + + public UnknownException(string message) + : base(message) + { + } + + public override string ice_id() => "::Ice::UnknownException"; +} + +/// +/// The dispatch failed with a that is not one of the special marshal-able local +/// exception. +/// +public sealed class UnknownLocalException : UnknownException +{ + public UnknownLocalException(string message) + : base(message) + { + } + + public override string ice_id() => "::Ice::UnknownLocalException"; +} + +/// +/// The dispatch returned a that was not declared in the operation's exception +/// specification. +/// +public sealed class UnknownUserException : UnknownException +{ + public UnknownUserException(string message) + : base(message) + { + } + + public override string ice_id() => "::Ice::UnknownUserException"; +} + +// +// Protocol exceptions +// + +/// +/// The base class for Ice protocol exceptions. +/// +public class ProtocolException : LocalException +{ + public ProtocolException(string? message = null, System.Exception? innerException = null) + : base(message, innerException) + { + } + + public override string ice_id() => "::Ice::ProtocolException"; +} + +/// +/// This exception indicates that the connection has been gracefully closed by the server. +/// The operation call that caused this exception has not been executed by the server. In most cases you will not get +/// this exception because the client will automatically retry the operation call in case the server shut down the +/// connection. However, if upon retry the server shuts down the connection again, and the retry limit has been reached, +/// then this exception is propagated to the application code. +/// +public sealed class CloseConnectionException : ProtocolException +{ + public CloseConnectionException() + : base(message: "Connection closed by the peer.", innerException: null) + { + } + + public override string ice_id() => "::Ice::CloseConnectionException"; +} + +/// +/// A datagram exceeds the configured size. +/// This exception is raised if a datagram exceeds the configured send or receive buffer size, or exceeds the maximum +/// payload size of a UDP packet (65507 bytes). +/// +public sealed class DatagramLimitException : ProtocolException +{ + public DatagramLimitException() + : base(message: "Datagram limit exceeded.", innerException: null) + { + } + + public override string ice_id() => "::Ice::DatagramLimitException"; +} + +/// +/// This exception reports an error during marshaling or unmarshaling. +/// +public sealed class MarshalException : ProtocolException +{ + public MarshalException(string message, System.Exception? innerException = null) + : base(message, innerException) + { + } + + public override string ice_id() => "::Ice::MarshalException"; +} + +// +// Timeout exceptions +// + +/// This exception indicates a timeout condition. +public class TimeoutException : LocalException +{ + public TimeoutException(string? message = null, System.Exception? innerException = null) + : base(message ?? "Operation timed out.", innerException) + { + } + + public override string ice_id() => "::Ice::TimeoutException"; +} + +/// This exception indicates a connection closure timeout condition. +public sealed class CloseTimeoutException : TimeoutException +{ + public CloseTimeoutException() + : base("Close timed out.") + { + } + + public override string ice_id() => "::Ice::CloseTimeoutException"; +} + +/// +/// This exception indicates a connection establishment timeout condition. +/// +public sealed class ConnectTimeoutException : TimeoutException +{ + public ConnectTimeoutException() + : base("Connect timed out.") + { + } + + public override string ice_id() => "::Ice::ConnectTimeoutException"; +} + +/// +/// This exception indicates that an invocation failed because it timed out. +/// +public sealed class InvocationTimeoutException : TimeoutException +{ + public InvocationTimeoutException() + : base("Invocation timed out.") + { + } + + public override string ice_id() => "::Ice::InvocationTimeoutException"; +} + +// +// Syscall exceptions +// + +/// +/// This exception is raised if a system error occurred in the server or client process. +/// +public class SyscallException : LocalException +{ + public SyscallException(string? message = null, System.Exception? innerException = null) + : base(message, innerException) + { + } + + public SyscallException(System.Exception innerException) + : base(innerException) + { + } + + public override string ice_id() => "::Ice::SyscallException"; +} + +/// +/// This exception indicates a connection failure. +/// +public class ConnectFailedException : SocketException +{ + public ConnectFailedException(System.Exception? innerException = null) + : base(innerException) + { + } + + public override string ice_id() => "::Ice::ConnectFailedException"; +} + +/// +/// This exception indicates a lost connection. +/// +public sealed class ConnectionLostException : SocketException +{ + public ConnectionLostException(System.Exception? innerException = null) + : base(innerException) + { + } + + public override string ice_id() => "::Ice::ConnectionLostException"; +} + +/// +/// This exception indicates a connection failure for which the server host actively refuses a connection. +/// +public sealed class ConnectionRefusedException : ConnectFailedException +{ + public ConnectionRefusedException(System.Exception? innerException = null) + : base(innerException) + { + } + + public override string ice_id() => "::Ice::ConnectionRefusedException"; +} + +/// +/// This exception indicates a DNS problem. +/// +public sealed class DNSException : SyscallException +{ + public DNSException(string host, System.Exception? innerException = null) + : base($"Cannot resolve host '{host}'", innerException) + { + } + + public override string ice_id() => "::Ice::DNSException"; +} + +/// This exception indicates a file error. +public sealed class FileException : SyscallException +{ + public FileException(string message, System.Exception innerException) + : base(message, innerException) + { + } + + public override string ice_id() => "::Ice::FileException"; +} + +/// +/// This exception indicates a socket error. +/// +public class SocketException : SyscallException +{ + public SocketException(System.Exception? innerException = null) + : base(message: null, innerException) + { + } + + public override string ice_id() => "::Ice::SocketException"; +} + +// +// Other leaf local exceptions in alphabetical order. +// + +/// +/// An attempt was made to register something more than once with the Ice run time. +/// This exception is raised if an attempt is made to register a servant, servant locator, facet, value factory, +/// plug-in, object adapter (etc.) more than once for the same ID. +/// +public sealed class AlreadyRegisteredException : LocalException +{ + public string kindOfObject { get; } + public string id { get; } + + public AlreadyRegisteredException(string kindOfObject, string id) + : base($"Another {kindOfObject} is already registered with ID '{id}'.") + { + this.kindOfObject = kindOfObject; + this.id = id; + } + + public override string ice_id() => "::Ice::AlreadyRegisteredException"; +} + +/// +/// This exception is raised if the Communicator has been destroyed. +/// +public sealed class CommunicatorDestroyedException : LocalException +{ + public CommunicatorDestroyedException() + : base("Communicator destroyed.") + { + } + + public override string ice_id() => "::Ice::CommunicatorDestroyedException"; +} + +/// +/// This exception indicates that a connection was closed forcefully. +/// +public sealed class ConnectionAbortedException : LocalException +{ + public bool closedByApplication { get; } + + public ConnectionAbortedException(string message, bool closedByApplication) + : base(message, innerException: null) => + this.closedByApplication = closedByApplication; + + public override string ice_id() => "::Ice::ConnectionAbortedException"; +} + +/// +/// This exception indicates that a connection was closed gracefully. +/// +public sealed class ConnectionClosedException : LocalException +{ + public bool closedByApplication { get; } + + public ConnectionClosedException(string message, bool closedByApplication) + : base(message, innerException: null) => + this.closedByApplication = closedByApplication; + + public override string ice_id() => "::Ice::ConnectionClosedException"; +} + +/// +/// This exception indicates that a connection was aborted by the idle check. +/// +public sealed class ConnectionIdleException : LocalException +{ + public ConnectionIdleException(string message) + : base(message, innerException: null) + { + } + + public override string ice_id() => "::Ice::ConnectionIdleException"; +} + +/// +/// This exception is raised if an unsupported feature is used. +/// +public sealed class FeatureNotSupportedException : LocalException +{ + public FeatureNotSupportedException(string message) + : base(message) + { + } + + public override string ice_id() => "::Ice::FeatureNotSupportedException"; +} + +/// +/// This exception indicates that an attempt has been made to change the connection properties of a fixed proxy. +/// +public sealed class FixedProxyException : LocalException +{ + public FixedProxyException() + : base("Cannot change the connection properties of a fixed proxy.") + { + } + + public override string ice_id() => "::Ice::FixedProxyException"; +} + +/// +/// This exception is raised when a failure occurs during initialization. +/// +public sealed class InitializationException : LocalException +{ + public InitializationException(string message, System.Exception? innerException = null) + : base(message, innerException) + { + } + + public override string ice_id() => "::Ice::InitializationException"; +} + +/// +/// This exception indicates that an asynchronous invocation failed because it was canceled explicitly by the user. +/// +public sealed class InvocationCanceledException : LocalException +{ + public InvocationCanceledException() + : base("Invocation canceled.") + { + } + + public override string ice_id() => "::Ice::InvocationCanceledException"; +} + +/// +/// This exception is raised if no suitable endpoint is available. +/// +public sealed class NoEndpointException : LocalException +{ + public NoEndpointException(string message) + : base(message) + { + } + + public NoEndpointException(ObjectPrx proxy) + : base($"No suitable endpoint available for proxy '{proxy}'.") + { + } + + public override string ice_id() => "::Ice::NoEndpointException"; +} + +/// +/// An attempt was made to find or deregister something that is not registered with the Ice run time or Ice locator. +/// This exception is raised if an attempt is made to remove a servant, servant locator, facet, value factory, plug-in, +/// object adapter (etc.) that is not currently registered. It's also raised if the Ice locator can't find an object or +/// object adapter when resolving an indirect proxy or when an object adapter is activated. +/// +public sealed class NotRegisteredException : LocalException +{ + public string kindOfObject { get; } + public string id { get; } + + public NotRegisteredException(string kindOfObject, string id) + : base($"No {kindOfObject} is registered with ID '{id}'.") + { + this.kindOfObject = kindOfObject; + this.id = id; + } + + public override string ice_id() => "::Ice::NotRegisteredException"; +} + +/// +/// This exception is raised if an attempt is made to use a deactivated ObjectAdapter. +/// +public sealed class ObjectAdapterDeactivatedException : LocalException +{ + public ObjectAdapterDeactivatedException(string name) + : base($"Object adapter '{name}' is deactivated.") + { + } + + public override string ice_id() => "::Ice::ObjectAdapterDeactivatedException"; +} + +/// +/// This exception is raised if an ObjectAdapter cannot be activated. +/// This happens if the Locator detects another active ObjectAdapter with the same adapter ID. +/// +public sealed class ObjectAdapterIdInUseException : LocalException +{ + public ObjectAdapterIdInUseException(string adapterId) + : base($"An object adapter with adapter ID '{adapterId}' is already active.") + { + } + + public override string ice_id() => "::Ice::ObjectAdapterIdInUseException"; +} + +/// +/// Reports a failure that occurred while parsing a string. +/// +public sealed class ParseException : LocalException +{ + public ParseException(string message, System.Exception? innerException = null) + : base(message, innerException) + { + } + + public override string ice_id() => "::Ice::ParseException"; +} + +/// +/// This exception indicates that a failure occurred while initializing a plug-in. +/// +public sealed class PluginInitializationException : LocalException +{ + public PluginInitializationException(string message, System.Exception? innerException = null) + : base(message, innerException) + { + } + + public override string ice_id() => "::Ice::PluginInitializationException"; +} + +/// +/// This exception indicates a failure in a security subsystem. +/// +public sealed class SecurityException : LocalException +{ + public SecurityException(string message, System.Exception? innerException = null) + : base(message, innerException) + { + } + + public override string ice_id() => "::Ice::SecurityException"; +} + +/// +/// The operation can only be invoked with a two-way request. +/// This exception is raised if an attempt is made to invoke an operation with ice_oneway, ice_batchOneway, +/// ice_datagram, or ice_batchDatagram and the operation has a return value, out-parameters, or an exception +/// specification. +/// +public sealed class TwowayOnlyException : LocalException +{ + public TwowayOnlyException(string operation) + : base($"Cannot invoke operation '{operation}' with a oneway, batchOneway, datagram, or batchDatagram proxy.") + { + } + + public override string ice_id() => "::Ice::TwowayOnlyException"; +} diff --git a/csharp/src/Ice/LoggerPlugin.cs b/csharp/src/Ice/LoggerPlugin.cs index dc0fe6d9749..da62aa16d09 100644 --- a/csharp/src/Ice/LoggerPlugin.cs +++ b/csharp/src/Ice/LoggerPlugin.cs @@ -19,16 +19,12 @@ public class LoggerPlugin : Plugin { if (communicator == null) { - PluginInitializationException ex = new PluginInitializationException(); - ex.reason = "Communicator cannot be null"; - throw ex; + throw new PluginInitializationException("Communicator cannot be null."); } if (logger == null) { - PluginInitializationException ex = new PluginInitializationException(); - ex.reason = "Logger cannot be null"; - throw ex; + throw new PluginInitializationException("Logger cannot be null."); } Ice.Internal.Instance instance = communicator.instance; diff --git a/csharp/src/Ice/Object.cs b/csharp/src/Ice/Object.cs index ddc00aa8e08..c78ea27298a 100644 --- a/csharp/src/Ice/Object.cs +++ b/csharp/src/Ice/Object.cs @@ -172,10 +172,7 @@ public static void iceCheckMode(OperationMode expected, OperationMode received) } else { - MarshalException ex = new MarshalException(); - ex.reason = "unexpected operation mode. expected = " + operationModeToString(expected) + - " received = " + operationModeToString(received); - throw ex; + throw new MarshalException($"unexpected operation mode: expected = {operationModeToString(expected)} received = {operationModeToString(received)}"); } } } diff --git a/csharp/src/Ice/ObjectAdapter.cs b/csharp/src/Ice/ObjectAdapter.cs index 7dce6ce5ced..c263c14836b 100644 --- a/csharp/src/Ice/ObjectAdapter.cs +++ b/csharp/src/Ice/ObjectAdapter.cs @@ -436,7 +436,7 @@ public ObjectPrx addFacet(Object obj, Identity ident, string facet) { checkForDeactivation(); checkIdentity(ident); - checkServant(obj); + ArgumentNullException.ThrowIfNull(obj); // // Create a copy of the Identity argument, in case the caller @@ -501,7 +501,7 @@ public ObjectPrx addFacetWithUUID(Object servant, string facet) /// public void addDefaultServant(Ice.Object servant, string category) { - checkServant(servant); + ArgumentNullException.ThrowIfNull(servant); lock (this) { @@ -1198,9 +1198,7 @@ internal ObjectAdapter( _state = StateDestroyed; _incomingConnectionFactories = []; - InitializationException ex = new InitializationException(); - ex.reason = "object adapter `" + _name + "' requires configuration"; - throw ex; + throw new InitializationException($"Object adapter '{name}' requires configuration."); } _id = properties.getProperty(_name + ".AdapterId"); @@ -1215,11 +1213,11 @@ internal ObjectAdapter( { _reference = _instance.referenceFactory().create("dummy " + proxyOptions, ""); } - catch (ProxyParseException) + catch (ParseException ex) { - InitializationException ex = new InitializationException(); - ex.reason = "invalid proxy options `" + proxyOptions + "' for object adapter `" + _name + "'"; - throw ex; + throw new InitializationException( + $"Invalid proxy options '{proxyOptions}' for object adapter '{_name}'.", + ex); } { @@ -1258,10 +1256,9 @@ internal ObjectAdapter( // if (_routerInfo.getAdapter() is not null) { - AlreadyRegisteredException ex = new AlreadyRegisteredException(); - ex.kindOfObject = "object adapter with router"; - ex.id = Util.identityToString(router.ice_getIdentity(), _instance.toStringMode()); - throw ex; + throw new AlreadyRegisteredException( + "object adapter with router", + Util.identityToString(router.ice_getIdentity(), _instance.toStringMode())); } // @@ -1333,7 +1330,7 @@ internal static void checkIdentity(Identity ident) { if (ident.name.Length == 0) { - throw new IllegalIdentityException(ident); + throw new ArgumentException("The name of an Ice object identity cannot be empty.", nameof(ident)); } } @@ -1368,17 +1365,7 @@ private void checkForDeactivation() { if (_state >= StateDeactivating) { - ObjectAdapterDeactivatedException ex = new ObjectAdapterDeactivatedException(); - ex.name = getName(); - throw ex; - } - } - - private static void checkServant(Object servant) - { - if (servant is null) - { - throw new IllegalServantException("cannot add null servant to Object Adapter"); + throw new ObjectAdapterDeactivatedException(getName()); } } @@ -1397,7 +1384,7 @@ private List parseEndpoints(string endpts, bool oaEndpoints) { if (endpoints.Count != 0) { - throw new EndpointParseException("invalid empty object adapter endpoint"); + throw new ParseException("invalid empty object adapter endpoint"); } break; } @@ -1447,14 +1434,14 @@ private List parseEndpoints(string endpts, bool oaEndpoints) if (end == beg) { - throw new EndpointParseException("invalid empty object adapter endpoint"); + throw new ParseException("invalid empty object adapter endpoint"); } string s = endpts.Substring(beg, (end) - (beg)); EndpointI endp = _instance.endpointFactoryManager().create(s, oaEndpoints); if (endp is null) { - throw new EndpointParseException("invalid object adapter endpoint `" + s + "'"); + throw new ParseException($"invalid object adapter endpoint {s}'"); } endpoints.Add(endp); @@ -1573,10 +1560,7 @@ private void updateLocatorRegistry(LocatorInfo? locatorInfo, ObjectPrx? proxy) _instance.initializationData().logger!.trace(_instance.traceLevels().locationCat, s.ToString()); } - NotRegisteredException ex1 = new NotRegisteredException(); - ex1.kindOfObject = "object adapter"; - ex1.id = _id; - throw ex1; + throw new NotRegisteredException("object adapter", _id); } catch (InvalidReplicaGroupIdException) { @@ -1588,10 +1572,7 @@ private void updateLocatorRegistry(LocatorInfo? locatorInfo, ObjectPrx? proxy) _instance.initializationData().logger!.trace(_instance.traceLevels().locationCat, s.ToString()); } - NotRegisteredException ex1 = new NotRegisteredException(); - ex1.kindOfObject = "replica group"; - ex1.id = _replicaGroupId; - throw ex1; + throw new NotRegisteredException("replica group", _replicaGroupId); } catch (AdapterAlreadyActiveException) { @@ -1603,9 +1584,7 @@ private void updateLocatorRegistry(LocatorInfo? locatorInfo, ObjectPrx? proxy) _instance.initializationData().logger!.trace(_instance.traceLevels().locationCat, s.ToString()); } - ObjectAdapterIdInUseException ex1 = new ObjectAdapterIdInUseException(); - ex1.id = _id; - throw; + throw new ObjectAdapterIdInUseException(_id); } catch (ObjectAdapterDeactivatedException) { diff --git a/csharp/src/Ice/OutputStream.cs b/csharp/src/Ice/OutputStream.cs index 54bc1a98107..69470ef289f 100644 --- a/csharp/src/Ice/OutputStream.cs +++ b/csharp/src/Ice/OutputStream.cs @@ -376,7 +376,7 @@ public void writeEncapsulation(byte[] v) { if (v.Length < 6) { - throw new EncapsulationException(); + throw new MarshalException($"A byte sequence with {v.Length} bytes is not a valid encapsulation."); } expand(v.Length); _buf.b.put(v); diff --git a/csharp/src/Ice/PluginManagerI.cs b/csharp/src/Ice/PluginManagerI.cs index 220290d31a3..6bb3c9e1b80 100644 --- a/csharp/src/Ice/PluginManagerI.cs +++ b/csharp/src/Ice/PluginManagerI.cs @@ -44,9 +44,7 @@ public void initializePlugins() { if (_initialized) { - InitializationException ex = new InitializationException(); - ex.reason = "plug-ins already initialized"; - throw ex; + throw new InitializationException("Plug-ins already initialized."); } // @@ -67,7 +65,7 @@ public void initializePlugins() } catch (System.Exception ex) { - throw new PluginInitializationException(String.Format("plugin `{0}' initialization failed", p.name), ex); + throw new PluginInitializationException($"Plugin '{p.name}' initialization failed.", ex); } initializedPlugins.Add(p.plugin); } @@ -124,10 +122,7 @@ public Plugin getPlugin(string name) return p; } - NotRegisteredException ex = new NotRegisteredException(); - ex.id = name; - ex.kindOfObject = _kindOfObject; - throw ex; + throw new NotRegisteredException(_kindOfObject, name); } } @@ -142,10 +137,7 @@ public void addPlugin(string name, Plugin plugin) if (findPlugin(name) is not null) { - AlreadyRegisteredException ex = new AlreadyRegisteredException(); - ex.id = name; - ex.kindOfObject = _kindOfObject; - throw ex; + throw new AlreadyRegisteredException(_kindOfObject, name); } _plugins.Add(new PluginInfo(name, plugin)); @@ -254,9 +246,7 @@ public void loadPlugins(ref string[] cmdArgs) if (findPlugin(loadOrder[i]) is not null) { - PluginInitializationException e = new PluginInitializationException(); - e.reason = "plug-in `" + loadOrder[i] + "' already loaded"; - throw e; + throw new PluginInitializationException($"Plug-in '{loadOrder[i]}' already loaded."); } string key = "Ice.Plugin." + loadOrder[i] + ".clr"; @@ -278,9 +268,7 @@ public void loadPlugins(ref string[] cmdArgs) } else { - PluginInitializationException e = new PluginInitializationException(); - e.reason = "plug-in `" + loadOrder[i] + "' not defined"; - throw e; + throw new PluginInitializationException($"Plug-in '{loadOrder[i]}' not defined."); } } @@ -357,11 +345,9 @@ private void loadPlugin(string name, string pluginSpec, ref string[] cmdArgs) { args = Ice.UtilInternal.Options.split(pluginSpec); } - catch (Ice.UtilInternal.Options.BadQuote ex) + catch (ParseException ex) { - PluginInitializationException e = new PluginInitializationException(); - e.reason = "invalid arguments for plug-in `" + name + "':\n" + ex.Message; - throw e; + throw new PluginInitializationException($"Invalid arguments for plug-in '{name}'.", ex); } Debug.Assert(args.Length > 0); @@ -411,9 +397,7 @@ private void loadPlugin(string name, string pluginSpec, ref string[] cmdArgs) } if (sepPos == -1) { - PluginInitializationException e = new PluginInitializationException(); - e.reason = err + "invalid entry point format"; - throw e; + throw new PluginInitializationException($"{err}invalid entry point format"); } System.Reflection.Assembly? pluginAssembly = null; @@ -451,9 +435,7 @@ private void loadPlugin(string name, string pluginSpec, ref string[] cmdArgs) } catch (System.Exception ex) { - PluginInitializationException e = new PluginInitializationException(); - e.reason = err + "unable to load assembly: `" + assemblyName + "': " + ex.ToString(); - throw e; + throw new PluginInitializationException($"{err}unable to load assembly '{assemblyName}'.", ex); } // @@ -466,9 +448,7 @@ private void loadPlugin(string name, string pluginSpec, ref string[] cmdArgs) } catch (System.Exception ex) { - PluginInitializationException e = new PluginInitializationException(ex); - e.reason = err + "GetType failed for `" + className + "'"; - throw e; + throw new PluginInitializationException($"{err}GetType failed for '{className}'.", ex); } try @@ -476,53 +456,32 @@ private void loadPlugin(string name, string pluginSpec, ref string[] cmdArgs) pluginFactory = (PluginFactory)Ice.Internal.AssemblyUtil.createInstance(c); if (pluginFactory is null) { - PluginInitializationException e = new PluginInitializationException(); - e.reason = err + "can't find constructor for `" + className + "'"; - throw e; + throw new PluginInitializationException($"{err}can't find constructor for '{className}'."); } } - catch (InvalidCastException ex) - { - PluginInitializationException e = new PluginInitializationException(ex); - e.reason = err + "InvalidCastException to Ice.PluginFactory"; - throw e; - } - catch (UnauthorizedAccessException ex) - { - PluginInitializationException e = new PluginInitializationException(ex); - e.reason = err + "UnauthorizedAccessException: " + ex.ToString(); - throw e; - } catch (System.Exception ex) { - PluginInitializationException e = new PluginInitializationException(ex); - e.reason = err + "System.Exception: " + ex.ToString(); - throw e; + throw new PluginInitializationException($"{err}SystemException", ex); } } - Plugin? plugin = null; + Plugin? plugin; try { plugin = pluginFactory.create(_communicator, name, args); } - catch (PluginInitializationException ex) + catch (PluginInitializationException) { - ex.reason = err + ex.reason; throw; } catch (System.Exception ex) { - PluginInitializationException e = new PluginInitializationException(ex); - e.reason = err + "System.Exception in factory.create: " + ex.ToString(); - throw e; + throw new PluginInitializationException($"{err}System.Exception in factory.create", ex); } if (plugin is null) { - PluginInitializationException ex = new PluginInitializationException(); - ex.reason = err + "factory.create returned null plug-in"; - throw ex; + throw new PluginInitializationException($"{err}factory.create returned null plug-in"); } _plugins.Add(new PluginInfo(name, plugin)); diff --git a/csharp/src/Ice/Properties.cs b/csharp/src/Ice/Properties.cs index df8caeb7e4f..af2ed9e3522 100644 --- a/csharp/src/Ice/Properties.cs +++ b/csharp/src/Ice/Properties.cs @@ -477,9 +477,7 @@ public void load(string file) } catch (IOException ex) { - var fe = new FileException(ex); - fe.path = file; - throw fe; + throw new FileException($"Cannot read '{file}'", ex); } } diff --git a/csharp/src/Ice/Proxy.cs b/csharp/src/Ice/Proxy.cs index e0c66bc08d6..adf21a27764 100644 --- a/csharp/src/Ice/Proxy.cs +++ b/csharp/src/Ice/Proxy.cs @@ -853,7 +853,7 @@ public ObjectPrx ice_identity(Identity newIdentity) { if (newIdentity.name.Length == 0) { - throw new IllegalIdentityException(); + throw new ArgumentException("The name of an Ice object identity cannot be empty.", nameof(newIdentity)); } if (newIdentity == _reference.getIdentity()) { @@ -1806,7 +1806,7 @@ public class ObjectPrxHelper : ObjectPrxHelperBase /// The communicator of the new proxy. /// The string representation of the proxy. /// The new proxy. - /// Thrown when is not a valid proxy string. + /// Thrown when is not a valid proxy string. /// public static ObjectPrx createProxy(Communicator communicator, string proxyString) { @@ -1814,7 +1814,7 @@ public static ObjectPrx createProxy(Communicator communicator, string proxyStrin return reference is not null ? new ObjectPrxHelper(reference) : - throw new ProxyParseException("Invalid empty proxy string."); + throw new ParseException("Invalid empty proxy string."); } /// Casts a proxy to {@link ObjectPrx}. This call contacts diff --git a/csharp/src/Ice/SSL/RFC2253.cs b/csharp/src/Ice/SSL/RFC2253.cs index 5e905139e75..9dcc9823317 100644 --- a/csharp/src/Ice/SSL/RFC2253.cs +++ b/csharp/src/Ice/SSL/RFC2253.cs @@ -12,15 +12,6 @@ namespace Ice.SSL; internal class RFC2253 { - public class ParseException : System.Exception - { - public ParseException(string reason) => this.reason = reason; - - internal string ice_id() => "::RFC2253::ParseException"; - - internal readonly string reason; - } - internal struct RDNPair { internal string key; diff --git a/csharp/src/Ice/SSL/SSLEngine.cs b/csharp/src/Ice/SSL/SSLEngine.cs index 3d02eae781e..29430f19074 100644 --- a/csharp/src/Ice/SSL/SSLEngine.cs +++ b/csharp/src/Ice/SSL/SSLEngine.cs @@ -195,7 +195,7 @@ internal void verifyPeer(ConnectionInfo info, string description) _logger.trace(_securityTraceCategory, msg); } - throw new Ice.SecurityException($"IceSSL: {msg}"); + throw new SecurityException($"IceSSL: {msg}"); } } diff --git a/csharp/src/Ice/SSL/TransceiverI.cs b/csharp/src/Ice/SSL/TransceiverI.cs index c99c4229a28..ab11614cab9 100644 --- a/csharp/src/Ice/SSL/TransceiverI.cs +++ b/csharp/src/Ice/SSL/TransceiverI.cs @@ -393,15 +393,13 @@ private bool startAuthenticate(Ice.Internal.AsyncCallback callback, object state if (Ice.Internal.Network.connectionLost(ex)) { // This situation occurs when connectToSelf is called; the "remote" end closes the socket immediately. - throw new Ice.ConnectionLostException(); + throw new ConnectionLostException(ex); } - throw new Ice.SocketException(ex); + throw new SocketException(ex); } catch (AuthenticationException ex) { - var e = new Ice.SecurityException(ex); - e.reason = ex.Message; - throw e; + throw new SecurityException("Authentication failure.", ex); } catch (Exception ex) { @@ -437,11 +435,9 @@ private void finishAuthenticate() } catch (AuthenticationException ex) { - var e = new Ice.SecurityException(ex); - e.reason = ex.Message; - throw e; + throw new SecurityException("Authentication failure.", ex); } - catch (Exception ex) + catch (System.Exception ex) { throw new Ice.SyscallException(ex); } diff --git a/csharp/src/Ice/SSL/TrustManager.cs b/csharp/src/Ice/SSL/TrustManager.cs index 060d75bac2f..d484ec44478 100644 --- a/csharp/src/Ice/SSL/TrustManager.cs +++ b/csharp/src/Ice/SSL/TrustManager.cs @@ -43,9 +43,9 @@ internal TrustManager(Ice.Communicator communicator) } } } - catch (RFC2253.ParseException ex) + catch (ParseException ex) { - throw new Ice.PluginInitializationException($"IceSSL: invalid property {key}:\n {ex.reason}"); + throw new InitializationException($"IceSSL: invalid property {key}", ex); } } @@ -176,10 +176,10 @@ internal bool verify(ConnectionInfo info, string description) } } } - catch (RFC2253.ParseException e) + catch (ParseException e) { _communicator.getLogger().warning( - $"IceSSL: unable to parse certificate DN `{subjectName}'\nreason: {e.reason}"); + $"IceSSL: unable to parse certificate DN `{subjectName}'\nreason: {e.Message}"); } // At this point we accept the connection if there are no explicit accept rules. diff --git a/csharp/src/Ice/ThreadHookPlugin.cs b/csharp/src/Ice/ThreadHookPlugin.cs index 9ea0b0260dc..790da2831a2 100644 --- a/csharp/src/Ice/ThreadHookPlugin.cs +++ b/csharp/src/Ice/ThreadHookPlugin.cs @@ -23,9 +23,7 @@ public class ThreadHookPlugin : Plugin { if (communicator == null) { - PluginInitializationException ex = new PluginInitializationException(); - ex.reason = "Communicator cannot be null"; - throw ex; + throw new PluginInitializationException("Communicator cannot be null."); } Ice.Internal.Instance instance = communicator.instance; diff --git a/csharp/src/Ice/UserException.cs b/csharp/src/Ice/UserException.cs new file mode 100644 index 00000000000..4b78b16f607 --- /dev/null +++ b/csharp/src/Ice/UserException.cs @@ -0,0 +1,38 @@ +// Copyright (c) ZeroC, Inc. + +#nullable enable + +namespace Ice; + +/// +/// Base class for exceptions defined in Slice. +/// +public abstract class UserException : Ice.Exception +{ + public virtual void iceWrite(OutputStream ostr) + { + ostr.startException(); + iceWriteImpl(ostr); + ostr.endException(); + } + + public virtual void iceRead(InputStream istr) + { + istr.startException(); + iceReadImpl(istr); + istr.endException(); + } + + public virtual bool iceUsesClasses() => false; + + /// + /// Constructs an Ice user exception. + /// + protected UserException(System.Exception? innerException = null) + : base(message: null, innerException) + { + } + + protected abstract void iceWriteImpl(OutputStream ostr); + protected abstract void iceReadImpl(InputStream istr); +} diff --git a/csharp/src/Ice/Util.cs b/csharp/src/Ice/Util.cs index adfb63c07fe..c174f687cb3 100644 --- a/csharp/src/Ice/Util.cs +++ b/csharp/src/Ice/Util.cs @@ -206,9 +206,7 @@ public static Identity stringToIdentity(string s) // // Extra unescaped slash found. // - IdentityParseException ex = new IdentityParseException(); - ex.str = "unescaped backslash in identity `" + s + "'"; - throw ex; + throw new ParseException($"unescaped backslash in identity string '{s}'"); } } pos++; @@ -223,9 +221,7 @@ public static Identity stringToIdentity(string s) } catch (ArgumentException e) { - IdentityParseException ex = new IdentityParseException(); - ex.str = "invalid identity name `" + s + "': " + e.Message; - throw ex; + throw new ParseException($"invalid name in identity string '{s}'", e); } } else @@ -236,9 +232,7 @@ public static Identity stringToIdentity(string s) } catch (ArgumentException e) { - IdentityParseException ex = new IdentityParseException(); - ex.str = "invalid category in identity `" + s + "': " + e.Message; - throw ex; + throw new ParseException($"invalid category in identity string '{s}'", e); } if (slash + 1 < s.Length) { @@ -248,9 +242,7 @@ public static Identity stringToIdentity(string s) } catch (ArgumentException e) { - IdentityParseException ex = new IdentityParseException(); - ex.str = "invalid name in identity `" + s + "': " + e.Message; - throw ex; + throw new ParseException($"invalid name in identity string '{s}'", e); } } else @@ -481,7 +473,7 @@ static private void stringToMajorMinor(string str, out byte major, out byte mino int pos = str.IndexOf('.'); if (pos == -1) { - throw new VersionParseException("malformed version value `" + str + "'"); + throw new ParseException($"malformed version value in '{str}'"); } string majStr = str.Substring(0, (pos) - (0)); @@ -493,14 +485,14 @@ static private void stringToMajorMinor(string str, out byte major, out byte mino majVersion = int.Parse(majStr, CultureInfo.InvariantCulture); minVersion = int.Parse(minStr, CultureInfo.InvariantCulture); } - catch (FormatException) + catch (FormatException ex) { - throw new VersionParseException("invalid version value `" + str + "'"); + throw new ParseException($"invalid version value in '{str}'", ex); } if (majVersion < 1 || majVersion > 255 || minVersion < 0 || minVersion > 255) { - throw new VersionParseException("range error in version `" + str + "'"); + throw new ParseException($"range error in version '{str}'"); } major = (byte)majVersion; diff --git a/csharp/src/Ice/UtilInternal/Options.cs b/csharp/src/Ice/UtilInternal/Options.cs index 305708ece04..cdb9da202d3 100644 --- a/csharp/src/Ice/UtilInternal/Options.cs +++ b/csharp/src/Ice/UtilInternal/Options.cs @@ -7,13 +7,6 @@ namespace Ice.UtilInternal; public sealed class Options { - public sealed class BadQuote : System.Exception - { - public BadQuote(string message) : base(message) - { - } - } - private enum State { Normal, DoubleQuote, SingleQuote, ANSIQuote }; static public string[] @@ -374,15 +367,15 @@ static public string[] } case State.SingleQuote: { - throw new BadQuote("missing closing single quote"); + throw new ParseException("missing closing single quote"); } case State.DoubleQuote: { - throw new BadQuote("missing closing double quote"); + throw new ParseException("missing closing double quote"); } case State.ANSIQuote: { - throw new BadQuote("unterminated $' quote"); + throw new ParseException("unterminated $' quote"); } default: { diff --git a/csharp/src/Ice/ValueFactory.cs b/csharp/src/Ice/ValueFactory.cs index 2246b4eec8e..1de40a97670 100644 --- a/csharp/src/Ice/ValueFactory.cs +++ b/csharp/src/Ice/ValueFactory.cs @@ -18,8 +18,8 @@ public interface ValueFactoryManager /// value was marshaled: /// If the value uses the "sliced" format, Ice ascends the class hierarchy until it finds a type that is recognized /// by a factory, or it reaches the least-derived type. If no factory is found that can create an instance, the run - /// time throws NoValueFactoryException. - /// If the value uses the "compact" format, Ice immediately raises NoValueFactoryException. + /// time throws a MarshalException. + /// If the value uses the "compact" format, Ice immediately raises a MarshalException. /// The following order is used to locate a factory for a type: /// /// The Ice run-time looks for a factory registered specifically for the type. diff --git a/csharp/src/IceBox/Service.cs b/csharp/src/IceBox/Service.cs index bb0ecb5098e..a580a825fe5 100644 --- a/csharp/src/IceBox/Service.cs +++ b/csharp/src/IceBox/Service.cs @@ -1,50 +1,24 @@ // Copyright (c) ZeroC, Inc. +#nullable enable + namespace IceBox; /// /// This exception is a general failure notification. -/// It is thrown for errors such as a service encountering an error -/// during initialization, or the service manager being unable to load a service executable. +/// It is thrown for errors such as a service encountering an error during initialization, or the service manager +/// being unable to load a service executable. /// -public class FailureException : Ice.LocalException +public sealed class FailureException : Ice.LocalException { - public string reason; - - private void _initDM() - { - this.reason = ""; - } - - public FailureException() - { - _initDM(); - } - - public FailureException(System.Exception ex) : base(ex) - { - _initDM(); - } + public string reason => Message; - private void _initDM(string reason) + public FailureException(string? message, System.Exception? innerException = null) + : base(message, innerException) { - this.reason = reason; } - public FailureException(string reason) - { - _initDM(reason); - } - - public FailureException(string reason, System.Exception ex) : base(ex) - { - _initDM(reason); - } - - public override string ice_id() - { - return "::IceBox::FailureException"; - } + public override string ice_id() => "::IceBox::FailureException"; } public interface Service diff --git a/csharp/src/IceBoxNet/ServiceManagerI.cs b/csharp/src/IceBoxNet/ServiceManagerI.cs index 1263f9c6c8f..ce2c8e1bf4c 100644 --- a/csharp/src/IceBoxNet/ServiceManagerI.cs +++ b/csharp/src/IceBoxNet/ServiceManagerI.cs @@ -269,7 +269,7 @@ public int run() if (services.Count == 0) { - throw new FailureException("ServiceManager: configuration must include at least one IceBox service"); + throw new FailureException("ServiceManager: configuration must include at least one IceBox service."); } string[] loadOrder = properties.getIcePropertyAsList("IceBox.LoadOrder"); @@ -279,12 +279,9 @@ public int run() if (loadOrder[i].Length > 0) { string key = prefix + loadOrder[i]; - string value; - if (!services.TryGetValue(key, out value)) + if (!services.TryGetValue(key, out string value)) { - FailureException ex = new FailureException(); - ex.reason = "ServiceManager: no service definition for `" + loadOrder[i] + "'"; - throw ex; + throw new FailureException($"ServiceManager: no service definition for '{loadOrder[i]}'."); } servicesInfo.Add(new StartServiceInfo(loadOrder[i], value, _argv)); services.Remove(key); @@ -452,9 +449,7 @@ private void startService(string service, string entryPoint, string[] args) } if (sepPos == -1) { - FailureException e = new FailureException(); - e.reason = err + "invalid entry point format"; - throw e; + throw new FailureException($"{err}invalid entry point format."); } System.Reflection.Assembly serviceAssembly = null; @@ -487,9 +482,7 @@ private void startService(string service, string entryPoint, string[] args) } catch (Exception ex) { - FailureException e = new FailureException(ex); - e.reason = err + "unable to load assembly: " + assemblyName; - throw e; + throw new FailureException($"{err}unable to load assembly: {assemblyName}", ex); } // @@ -502,9 +495,7 @@ private void startService(string service, string entryPoint, string[] args) } catch (Exception ex) { - FailureException e = new FailureException(ex); - e.reason = err + "GetType failed for '" + className + "'"; - throw e; + throw new FailureException($"{err}GetType failed for '{className}'.", ex); } ServiceInfo info = new ServiceInfo(); @@ -611,9 +602,9 @@ private void startService(string service, string entryPoint, string[] args) } catch (MethodAccessException ex) { - FailureException e = new FailureException(ex); - e.reason = err + "unable to access service constructor " + className + "(Ice.Communicator)"; - throw e; + throw new FailureException( + $"{err}unable to access service constructor {className}(Ice.Communicator).", + ex); } } else @@ -626,16 +617,12 @@ private void startService(string service, string entryPoint, string[] args) info.service = (Service)Ice.Internal.AssemblyUtil.createInstance(c); if (info.service == null) { - FailureException e = new FailureException(); - e.reason = err + "no default constructor for '" + className + "'"; - throw e; + throw new FailureException($"{err}no default constructor for '{className}'."); } } catch (UnauthorizedAccessException ex) { - FailureException e = new FailureException(ex); - e.reason = err + "unauthorized access to default service constructor for " + className; - throw e; + throw new FailureException($"{err}unauthorized access to default service constructor for '{className}'.", ex); } } } @@ -645,9 +632,7 @@ private void startService(string service, string entryPoint, string[] args) } catch (InvalidCastException ex) { - FailureException e = new FailureException(ex); - e.reason = err + "service does not implement IceBox.Service"; - throw e; + throw new FailureException($"{err}service does not implement IceBox.Service.", ex); } catch (System.Reflection.TargetInvocationException ex) { @@ -657,16 +642,12 @@ private void startService(string service, string entryPoint, string[] args) } else { - FailureException e = new FailureException(ex.InnerException); - e.reason = err + "exception in service constructor for " + className; - throw e; + throw new FailureException($"{err}exception in service constructor for '{className}'.", ex.InnerException); } } catch (Exception ex) { - FailureException e = new FailureException(ex); - e.reason = err + "exception in service constructor " + className; - throw e; + throw new FailureException($"{err}exception in service constructor for '{className}'.", ex); } try @@ -679,9 +660,7 @@ private void startService(string service, string entryPoint, string[] args) } catch (Exception ex) { - FailureException e = new FailureException(ex); - e.reason = "exception while starting service " + service; - throw e; + throw new FailureException($"{err}exception while starting service '{service}'.", ex); } info.status = ServiceStatus.Started; @@ -861,11 +840,9 @@ public StartServiceInfo(string service, string value, string[] serverArgs) { args = Ice.UtilInternal.Options.split(value); } - catch (Ice.UtilInternal.Options.BadQuote ex) + catch (Ice.ParseException ex) { - FailureException e = new FailureException(); - e.reason = "ServiceManager: invalid arguments for service `" + name + "':\n" + ex.Message; - throw e; + throw new FailureException($"ServiceManager: invalid arguments for service '{name}'.", ex); } Debug.Assert(args.Length > 0); diff --git a/csharp/test/Ice/ami/AllTests.cs b/csharp/test/Ice/ami/AllTests.cs index ee771b4d2cc..bd18d6b10a6 100644 --- a/csharp/test/Ice/ami/AllTests.cs +++ b/csharp/test/Ice/ami/AllTests.cs @@ -442,9 +442,9 @@ public static async Task allTestsAsync(global::Test.TestHelper helper, bool coll await t; test(false); } - catch (ConnectionManuallyClosedException ex) + catch (ConnectionClosedException ex) { - test(ex.graceful); + test(ex.closedByApplication); } test(p.opBatchCount() == 0); test(!tcs.Task.IsCompleted); @@ -770,7 +770,7 @@ public static async Task allTestsAsync(global::Test.TestHelper helper, bool coll // // Local case: start an operation and then close the connection gracefully on the client side // without waiting for the pending invocation to complete. There will be no retry and we expect the - // invocation to fail with ConnectionManuallyClosedException. + // invocation to fail with ConnectionClosedException. // p = (Test.TestIntfPrx)p.ice_connectionId("CloseGracefully"); // Start with a new connection. Connection con = p.ice_getConnection(); @@ -783,9 +783,9 @@ public static async Task allTestsAsync(global::Test.TestHelper helper, bool coll await t; test(false); } - catch (ConnectionManuallyClosedException ex) + catch (ConnectionClosedException ex) { - test(ex.graceful); + test(ex.closedByApplication); } p.finishDispatch(); @@ -808,7 +808,7 @@ public static async Task allTestsAsync(global::Test.TestHelper helper, bool coll { // // Local case: start an operation and then close the connection forcefully on the client side. - // There will be no retry and we expect the invocation to fail with ConnectionManuallyClosedException. + // There will be no retry and we expect the invocation to fail with ConnectionAbortedException. // p.ice_ping(); Connection con = p.ice_getConnection(); @@ -822,9 +822,9 @@ public static async Task allTestsAsync(global::Test.TestHelper helper, bool coll await t; test(false); } - catch (ConnectionManuallyClosedException ex) + catch (ConnectionAbortedException ex) { - test(!ex.graceful); + test(ex.closedByApplication); } p.finishDispatch(); diff --git a/csharp/test/Ice/background/AllTests.cs b/csharp/test/Ice/background/AllTests.cs index 325c2ff403e..1a59b2da05e 100644 --- a/csharp/test/Ice/background/AllTests.cs +++ b/csharp/test/Ice/background/AllTests.cs @@ -265,7 +265,7 @@ private static async Task connectTests(Configuration configuration, Test.Backgro { if (i == 0 || i == 2) { - configuration.connectorsException(new Ice.DNSException()); + configuration.connectorsException(new Ice.DNSException("dummy")); } else { diff --git a/csharp/test/Ice/exceptions/AllTests.cs b/csharp/test/Ice/exceptions/AllTests.cs index 80d3aab0adb..dbbb271bc93 100644 --- a/csharp/test/Ice/exceptions/AllTests.cs +++ b/csharp/test/Ice/exceptions/AllTests.cs @@ -108,9 +108,8 @@ public virtual void called() adapter.add(obj, Util.stringToIdentity("")); test(false); } - catch (IllegalIdentityException e) + catch (ArgumentException) { - test(e.id.name.Length == 0); } try @@ -118,7 +117,7 @@ public virtual void called() adapter.add(null, Util.stringToIdentity("x")); test(false); } - catch (IllegalServantException) + catch (ArgumentNullException) { } @@ -404,8 +403,9 @@ public virtual void called() thrower.throwMemoryLimitException(null); test(false); } - catch (MemoryLimitException) + catch (MarshalException ex) { + test(ex.Message.Contains("exceeds the maximum allowed")); } catch (Exception) { @@ -437,9 +437,11 @@ public virtual void called() { thrower2.throwMemoryLimitException(new byte[2 * 1024 * 1024]); // 2MB(no limits) } - catch (MemoryLimitException) + catch (MarshalException ex) { + test(ex.Message.Contains("exceeds the maximum allowed")); } + var thrower3 = Test.ThrowerPrxHelper.uncheckedCast( communicator.stringToProxy("thrower:" + helper.getTestEndpoint(2))); try diff --git a/csharp/test/Ice/invoke/BlobjectI.cs b/csharp/test/Ice/invoke/BlobjectI.cs index 82cb029368e..dd656b71d42 100644 --- a/csharp/test/Ice/invoke/BlobjectI.cs +++ b/csharp/test/Ice/invoke/BlobjectI.cs @@ -63,11 +63,7 @@ public override bool } else { - Ice.OperationNotExistException ex = new Ice.OperationNotExistException(); - ex.id = current.id; - ex.facet = current.facet; - ex.operation = current.operation; - throw ex; + throw new Ice.OperationNotExistException(); } } } @@ -122,11 +118,7 @@ public override Task } else { - Ice.OperationNotExistException ex = new Ice.OperationNotExistException(); - ex.id = current.id; - ex.facet = current.facet; - ex.operation = current.operation; - throw ex; + throw new Ice.OperationNotExistException(); } } } diff --git a/csharp/test/Ice/objects/AllTests.cs b/csharp/test/Ice/objects/AllTests.cs index 7af10b87b0a..93d300f2eb5 100644 --- a/csharp/test/Ice/objects/AllTests.cs +++ b/csharp/test/Ice/objects/AllTests.cs @@ -379,10 +379,10 @@ public static Test.InitialPrx allTests(global::Test.TestHelper helper) uoet.op(); test(false); } - catch (Ice.UnexpectedObjectException ex) + catch (Ice.MarshalException ex) { - test(ex.type == "::Test::AlsoEmpty"); - test(ex.expectedType == "::Test::Empty"); + test(ex.Message.Contains("'::Test::AlsoEmpty'")); + test(ex.Message.Contains("'::Test::Empty'")); } catch (System.Exception ex) { diff --git a/csharp/test/Ice/operations/BatchOneways.cs b/csharp/test/Ice/operations/BatchOneways.cs index a1d2a346f36..8083821ce98 100644 --- a/csharp/test/Ice/operations/BatchOneways.cs +++ b/csharp/test/Ice/operations/BatchOneways.cs @@ -73,7 +73,7 @@ internal static void batchOneways(global::Test.TestHelper helper, Test.MyClassPr { batch.opByteSOneway(bs1); } - catch (Ice.MemoryLimitException) + catch (Ice.MarshalException) { test(false); } diff --git a/csharp/test/Ice/proxy/AllTests.cs b/csharp/test/Ice/proxy/AllTests.cs index 66625e2917e..3791cc3afca 100644 --- a/csharp/test/Ice/proxy/AllTests.cs +++ b/csharp/test/Ice/proxy/AllTests.cs @@ -36,7 +36,7 @@ public class AllTests : global::Test.AllTests b1 = communicator.stringToProxy("\"test -f facet'"); test(false); } - catch (Ice.ProxyParseException) + catch (ParseException) { } b1 = communicator.stringToProxy("\"test -f facet\""); @@ -53,7 +53,7 @@ public class AllTests : global::Test.AllTests b1 = communicator.stringToProxy("test test"); test(false); } - catch (Ice.ProxyParseException) + catch (ParseException) { } b1 = communicator.stringToProxy("test\\040test"); @@ -63,7 +63,7 @@ public class AllTests : global::Test.AllTests b1 = communicator.stringToProxy("test\\777"); test(false); } - catch (Ice.IdentityParseException) + catch (ParseException) { } b1 = communicator.stringToProxy("test\\40test"); @@ -101,7 +101,7 @@ public class AllTests : global::Test.AllTests b1 = communicator.stringToProxy("\"\" test"); // Invalid trailing characters. test(false); } - catch (Ice.ProxyParseException) + catch (ParseException) { } try @@ -109,7 +109,7 @@ public class AllTests : global::Test.AllTests b1 = communicator.stringToProxy("test:"); // Missing endpoint. test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -121,7 +121,7 @@ public class AllTests : global::Test.AllTests b1 = communicator.stringToProxy("id@adapter test"); test(false); } - catch (Ice.ProxyParseException) + catch (ParseException) { } b1 = communicator.stringToProxy("category/test@adapter"); @@ -160,7 +160,7 @@ public class AllTests : global::Test.AllTests b1 = communicator.stringToProxy("id -f \"facet x"); test(false); } - catch (Ice.ProxyParseException) + catch (ParseException) { } try @@ -168,7 +168,7 @@ public class AllTests : global::Test.AllTests b1 = communicator.stringToProxy("id -f \'facet x"); test(false); } - catch (Ice.ProxyParseException) + catch (ParseException) { } b1 = communicator.stringToProxy("test -f facet:tcp"); @@ -191,7 +191,7 @@ public class AllTests : global::Test.AllTests b1 = communicator.stringToProxy("test -f facet@test @test"); test(false); } - catch (Ice.ProxyParseException) + catch (ParseException) { } b1 = communicator.stringToProxy("test"); @@ -230,7 +230,7 @@ public class AllTests : global::Test.AllTests communicator.stringToProxy("test:tcp@adapterId"); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } // This is an unknown endpoint warning, not a parse exception. @@ -240,7 +240,7 @@ public class AllTests : global::Test.AllTests // b1 = communicator.stringToProxy("test -f the:facet:tcp"); // test(false); //} - //catch(Ice.EndpointParseException) + //catch(ParseException) //{ //} try @@ -248,7 +248,7 @@ public class AllTests : global::Test.AllTests communicator.stringToProxy("test: :tcp"); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -260,7 +260,7 @@ public class AllTests : global::Test.AllTests communicator.createObjectAdapterWithEndpoints("BadAdapter", " : "); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -269,7 +269,7 @@ public class AllTests : global::Test.AllTests communicator.createObjectAdapterWithEndpoints("BadAdapter", "tcp: "); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -278,7 +278,7 @@ public class AllTests : global::Test.AllTests communicator.createObjectAdapterWithEndpoints("BadAdapter", ":tcp"); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -309,7 +309,7 @@ public class AllTests : global::Test.AllTests id = Ice.Util.stringToIdentity("xx\01FooBar"); test(false); } - catch (Ice.IdentityParseException) + catch (ParseException) { } @@ -319,7 +319,7 @@ public class AllTests : global::Test.AllTests id = Ice.Util.stringToIdentity("xx\\ud911"); test(false); } - catch (Ice.IdentityParseException) + catch (ParseException) { } @@ -830,9 +830,9 @@ public class AllTests : global::Test.AllTests cl20.ice_ping(); test(false); } - catch (Ice.UnsupportedEncodingException) + catch (MarshalException) { - // Server 2.0 endpoint doesn't support 1.1 version. + // Cannot marshal with the 2.0 encoding version. } string ref10 = "test -e 1.0:" + helper.getTestEndpoint(0); @@ -865,8 +865,10 @@ public class AllTests : global::Test.AllTests } catch (Ice.UnknownLocalException ex) { - // The server thrown an UnsupportedEncodingException - test(ex.unknown.IndexOf("UnsupportedEncodingException") > 0); + // TODO: remove UnsupportedEncodingException + test( + ex.unknown.Contains("MarshalException") || + ex.unknown.Contains("UnsupportedEncodingException")); } try @@ -886,8 +888,10 @@ public class AllTests : global::Test.AllTests } catch (Ice.UnknownLocalException ex) { - // The server thrown an UnsupportedEncodingException - test(ex.unknown.IndexOf("UnsupportedEncodingException") > 0); + // TODO: remove UnsupportedEncodingException + test( + ex.unknown.Contains("MarshalException") || + ex.unknown.Contains("UnsupportedEncodingException")); } output.WriteLine("ok"); @@ -901,7 +905,7 @@ public class AllTests : global::Test.AllTests cl20.ice_ping(); test(false); } - catch (Ice.UnsupportedProtocolException) + catch (FeatureNotSupportedException) { // Server 2.0 proxy doesn't support 1.0 version. } @@ -910,8 +914,8 @@ public class AllTests : global::Test.AllTests cl10 = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref10)); cl10.ice_ping(); - // 1.3 isn't supported but since a 1.3 proxy supports 1.1, the - // call will use the 1.1 protocol + // 1.3 isn't supported but since a 1.3 proxy supports 1.0, the + // call will use the 1.0 protocol ref13 = "test -p 1.3:" + helper.getTestEndpoint(0); cl13 = Test.MyClassPrxHelper.uncheckedCast(communicator.stringToProxy(ref13)); cl13.ice_ping(); @@ -927,7 +931,7 @@ public class AllTests : global::Test.AllTests communicator.stringToProxy("id:opaque -t 99 -v abcd -x abc"); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -937,7 +941,7 @@ public class AllTests : global::Test.AllTests communicator.stringToProxy("id:opaque"); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -947,7 +951,7 @@ public class AllTests : global::Test.AllTests communicator.stringToProxy("id:opaque -t 1 -t 1 -v abcd"); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -957,7 +961,7 @@ public class AllTests : global::Test.AllTests communicator.stringToProxy("id:opaque -t 1 -v abcd -v abcd"); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -967,7 +971,7 @@ public class AllTests : global::Test.AllTests communicator.stringToProxy("id:opaque -v abcd"); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -977,7 +981,7 @@ public class AllTests : global::Test.AllTests communicator.stringToProxy("id:opaque -t 1"); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -987,7 +991,7 @@ public class AllTests : global::Test.AllTests communicator.stringToProxy("id:opaque -t -v abcd"); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -997,7 +1001,7 @@ public class AllTests : global::Test.AllTests communicator.stringToProxy("id:opaque -t 1 -v"); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -1007,7 +1011,7 @@ public class AllTests : global::Test.AllTests communicator.stringToProxy("id:opaque -t x -v abcd"); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -1017,7 +1021,7 @@ public class AllTests : global::Test.AllTests communicator.stringToProxy("id:opaque -t -1 -v abcd"); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -1027,7 +1031,7 @@ public class AllTests : global::Test.AllTests communicator.stringToProxy("id:opaque -t 99 -v x?c"); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } @@ -1037,7 +1041,7 @@ public class AllTests : global::Test.AllTests communicator.stringToProxy("id:opaque -t 99 -v xc"); test(false); } - catch (Ice.EndpointParseException) + catch (ParseException) { } diff --git a/csharp/test/Ice/servantLocator/ServantLocatorAMDI.cs b/csharp/test/Ice/servantLocator/ServantLocatorAMDI.cs index 426b351b056..04aecec7d40 100644 --- a/csharp/test/Ice/servantLocator/ServantLocatorAMDI.cs +++ b/csharp/test/Ice/servantLocator/ServantLocatorAMDI.cs @@ -116,21 +116,15 @@ private void exception(Ice.Current current) } else if (current.operation == "unknownUserException") { - var ex = new Ice.UnknownUserException(); - ex.unknown = "reason"; - throw ex; + throw new Ice.UnknownUserException("reason"); } else if (current.operation == "unknownLocalException") { - var ex = new Ice.UnknownLocalException(); - ex.unknown = "reason"; - throw ex; + throw new Ice.UnknownLocalException("reason"); } else if (current.operation == "unknownException") { - var ex = new Ice.UnknownException(); - ex.unknown = "reason"; - throw ex; + throw new Ice.UnknownException("reason"); } else if (current.operation == "userException") { @@ -138,9 +132,7 @@ private void exception(Ice.Current current) } else if (current.operation == "localException") { - var ex = new Ice.SocketException(); - ex.error = 0; - throw ex; + throw new Ice.SocketException(); } else if (current.operation == "csException") { diff --git a/csharp/test/Ice/servantLocator/ServantLocatorI.cs b/csharp/test/Ice/servantLocator/ServantLocatorI.cs index 971f8c5ff66..1450019a575 100644 --- a/csharp/test/Ice/servantLocator/ServantLocatorI.cs +++ b/csharp/test/Ice/servantLocator/ServantLocatorI.cs @@ -114,21 +114,15 @@ private void exception(Ice.Current current) } else if (current.operation == "unknownUserException") { - var ex = new Ice.UnknownUserException(); - ex.unknown = "reason"; - throw ex; + throw new Ice.UnknownUserException("reason"); } else if (current.operation == "unknownLocalException") { - var ex = new Ice.UnknownLocalException(); - ex.unknown = "reason"; - throw ex; + throw new Ice.UnknownLocalException("reason"); } else if (current.operation == "unknownException") { - var ex = new Ice.UnknownException(); - ex.unknown = "reason"; - throw ex; + throw new Ice.UnknownException("reason"); } else if (current.operation == "userException") { @@ -136,9 +130,7 @@ private void exception(Ice.Current current) } else if (current.operation == "localException") { - var ex = new Ice.SocketException(); - ex.error = 0; - throw ex; + throw new Ice.SocketException(); } else if (current.operation == "csException") { diff --git a/csharp/test/Ice/slicing/objects/AllTests.cs b/csharp/test/Ice/slicing/objects/AllTests.cs index b774fc823d8..dec1ecd37b0 100644 --- a/csharp/test/Ice/slicing/objects/AllTests.cs +++ b/csharp/test/Ice/slicing/objects/AllTests.cs @@ -239,7 +239,7 @@ public static TestIntfPrx allTests(Test.TestHelper helper, bool collocated) testPrx.SBSUnknownDerivedAsSBaseCompact(); test(false); } - catch (Ice.NoValueFactoryException) + catch (Ice.MarshalException) { // Expected. } @@ -279,7 +279,7 @@ public static TestIntfPrx allTests(Test.TestHelper helper, bool collocated) } catch (AggregateException ae) { - test(ae.InnerException is Ice.NoValueFactoryException); + test(ae.InnerException is Ice.MarshalException); } } output.WriteLine("ok"); @@ -296,7 +296,7 @@ public static TestIntfPrx allTests(Test.TestHelper helper, bool collocated) test((o as Ice.UnknownSlicedValue).ice_getSlicedData() != null); testPrx.checkSUnknown(o); } - catch (Ice.NoValueFactoryException) + catch (Ice.MarshalException) { test(testPrx.ice_getEncodingVersion().Equals(Ice.Util.Encoding_1_0)); } @@ -321,14 +321,7 @@ public static TestIntfPrx allTests(Test.TestHelper helper, bool collocated) } catch (AggregateException ae) { - try - { - throw ae.InnerException; - } - catch (Ice.Exception ex) - { - test(ex.GetType().FullName == "Ice.NoValueFactoryException"); - } + test(ae.InnerException is Ice.MarshalException); } } else diff --git a/csharp/test/Ice/stream/AllTests.cs b/csharp/test/Ice/stream/AllTests.cs index 2b708b28dc7..eddc499d301 100644 --- a/csharp/test/Ice/stream/AllTests.cs +++ b/csharp/test/Ice/stream/AllTests.cs @@ -175,7 +175,7 @@ static public int allTests(global::Test.TestHelper helper) inS.readBool(); test(false); } - catch (Ice.UnmarshalOutOfBoundsException) + catch (Ice.MarshalException) { } } diff --git a/csharp/test/Ice/timeout/AllTests.cs b/csharp/test/Ice/timeout/AllTests.cs index a88a6a7a846..8f01b55af9c 100644 --- a/csharp/test/Ice/timeout/AllTests.cs +++ b/csharp/test/Ice/timeout/AllTests.cs @@ -163,10 +163,10 @@ public static async Task allTestsWithController(global::Test.TestHelper helper, connection.getInfo(); Thread.Sleep(10); } - catch (ConnectionManuallyClosedException ex) + catch (ConnectionClosedException ex) { // Expected. - test(ex.graceful); + test(ex.closedByApplication); break; } } diff --git a/csharp/test/IceUtil/inputUtil/Client.cs b/csharp/test/IceUtil/inputUtil/Client.cs index 68bb1b35411..2457961712a 100644 --- a/csharp/test/IceUtil/inputUtil/Client.cs +++ b/csharp/test/IceUtil/inputUtil/Client.cs @@ -62,7 +62,7 @@ public override void run(string[] argvs) args = Ice.UtilInternal.Options.split("-Dir=$'C:\\\\\\cM\\x66\\146i'"); // -Dir=$'C:\\\cM\x66\146i' test(args.Length == 1 && args[0] == "-Dir=C:\\\x000Dffi"); } - catch (Ice.UtilInternal.Options.BadQuote) + catch (Ice.ParseException) { test(false); } @@ -81,7 +81,7 @@ public override void run(string[] argvs) Ice.UtilInternal.Options.split(badQuoteCommands[i]); test(false); } - catch (Ice.UtilInternal.Options.BadQuote) + catch (Ice.ParseException) { } } diff --git a/java/test/src/main/java/test/Ice/proxy/AllTests.java b/java/test/src/main/java/test/Ice/proxy/AllTests.java index e9bb0f55d82..0cf72656137 100644 --- a/java/test/src/main/java/test/Ice/proxy/AllTests.java +++ b/java/test/src/main/java/test/Ice/proxy/AllTests.java @@ -920,8 +920,10 @@ public static MyClassPrx allTests(test.TestHelper helper) { cl.ice_invoke("ice_ping", com.zeroc.Ice.OperationMode.Normal, inEncaps); test(false); } catch (com.zeroc.Ice.UnknownLocalException ex) { - // The server thrown an UnsupportedEncodingException - test(ex.unknown.indexOf("UnsupportedEncodingException") > 0); + // TODO: remove UnsupportedEncodingException + test( + ex.unknown.indexOf("MarshalException") > 0 + || ex.unknown.indexOf("UnsupportedEncodingException") > 0); } try { @@ -936,8 +938,10 @@ public static MyClassPrx allTests(test.TestHelper helper) { cl.ice_invoke("ice_ping", com.zeroc.Ice.OperationMode.Normal, inEncaps); test(false); } catch (com.zeroc.Ice.UnknownLocalException ex) { - // The server thrown an UnsupportedEncodingException - test(ex.unknown.indexOf("UnsupportedEncodingException") > 0); + // TODO: remove UnsupportedEncodingException + test( + ex.unknown.indexOf("MarshalException") > 0 + || ex.unknown.indexOf("UnsupportedEncodingException") > 0); } out.println("ok"); diff --git a/swift/test/Ice/proxy/AllTests.swift b/swift/test/Ice/proxy/AllTests.swift index b7509bd3751..899b0c9afb2 100644 --- a/swift/test/Ice/proxy/AllTests.swift +++ b/swift/test/Ice/proxy/AllTests.swift @@ -743,8 +743,9 @@ public func allTests(_ helper: TestHelper) throws -> MyClassPrx { _ = try cl.ice_invoke(operation: "ice_ping", mode: Ice.OperationMode.Normal, inEncaps: inEncaps) try test(false) } catch let ex as Ice.UnknownLocalException { - // The server thrown an UnsupportedEncodingException - try test(ex.unknown.contains("UnsupportedEncodingException")) + // TODO: remove UnsupportedEncodingException + try test( + ex.unknown.contains("MarshalException") || ex.unknown.contains("UnsupportedEncodingException")) } do { @@ -759,8 +760,9 @@ public func allTests(_ helper: TestHelper) throws -> MyClassPrx { _ = try cl.ice_invoke(operation: "ice_ping", mode: Ice.OperationMode.Normal, inEncaps: inEncaps) try test(false) } catch let ex as Ice.UnknownLocalException { - // The server thrown an UnsupportedEncodingException - try test(ex.unknown.contains("UnsupportedEncodingException")) + // TODO: remove UnsupportedEncodingException + try test( + ex.unknown.contains("MarshalException") || ex.unknown.contains("UnsupportedEncodingException")) } writer.writeLine("ok")