// ********************************************************************** // // Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved. // // This copy of Ice is licensed to you under the terms described in the // ICE_LICENSE file included in this distribution. // // ********************************************************************** using System; using System.Globalization; using System.Runtime.Serialization; namespace IceInternal { public class Ex { public static void throwUOE(string expectedType, string actualType) { throw new Ice.UnexpectedObjectException( "expected element of type `" + expectedType + "' but received '" + actualType, actualType, expectedType); } public static void throwMemoryLimitException(int requested, int maximum) { throw new Ice.MemoryLimitException("requested " + requested + " bytes, maximum allowed is " + maximum + " bytes (see Ice.MessageSizeMax)"); } } } namespace Ice { /// /// Base class for Ice exceptions. /// [Serializable] public abstract class Exception : System.Exception, ICloneable { /// /// Creates and returns a copy of this exception. /// /// A copy of this exception. public object Clone() { return MemberwiseClone(); } /// /// Creates a default-initialized exception. /// public Exception() {} /// /// Creates a default-initialized exception and sets the InnerException /// property to the passed exception. /// /// The inner exception. public Exception(System.Exception ex) : base("", ex) {} /// /// Initializes a new instance of the exception with serialized data. /// /// Holds the serialized object data about the exception being thrown. /// Contains contextual information about the source or destination. protected Exception(SerializationInfo info, StreamingContext context) : base(info, context) {} /// /// ice_name() is deprecated, use ice_id() instead. /// Returns the name of this exception. /// /// The name of this exception. [Obsolete("ice_name() is deprecated, use ice_id() instead.")] public string ice_name() { return ice_id().Substring(2); } /// /// Returns the type id of this exception. /// /// The type id of this exception. public abstract string ice_id(); /// /// Returns a string representation of this exception, including /// any inner exceptions. /// /// The string representation of this exception. public override string ToString() { // // This prints the exception Java style. That is, the outermost // exception, "Caused by:" to the innermost exception. The // stack trace is not nicely indented as with Java, but // without string parsing (perhaps tokenize on "\n"), it // doesn't appear to be possible to reformat it. // System.IO.StringWriter sw = new System.IO.StringWriter(CultureInfo.CurrentCulture); IceUtilInternal.OutputBase op = new IceUtilInternal.OutputBase(sw); op.setUseTab(false); op.print(GetType().FullName); op.inc(); IceInternal.ValueWriter.write(this, op); sw.Write("\n"); sw.Write(StackTrace); System.Exception curr = InnerException; while(curr != null) { sw.Write("\nCaused by: "); sw.Write(curr.GetType().FullName); if(!(curr is Ice.Exception)) { sw.Write(": "); sw.Write(curr.Message); } sw.Write("\n"); sw.Write(curr.StackTrace); curr = curr.InnerException; } return sw.ToString(); } } /// /// Base class for local exceptions. /// [Serializable] public abstract class LocalException : Exception { /// /// Creates a default-initialized local exception. /// public LocalException() {} /// /// Creates a default-initialized local exception and sets the InnerException /// property to the passed exception. /// /// The inner exception. public LocalException(System.Exception ex) : base(ex) {} /// /// Initializes a new instance of the exception with serialized data. /// /// Holds the serialized object data about the exception being thrown. /// Contains contextual information about the source or destination. protected LocalException(SerializationInfo info, StreamingContext context) : base(info, context) {} } /// /// Base class for Ice run-time exceptions. /// [Serializable] public abstract class SystemException : Exception { /// /// Creates a default-initialized run-time exception. /// public SystemException() {} /// /// Creates a default-initialized run-time exception and sets the InnerException /// property to the passed exception. /// /// The inner exception. public SystemException(System.Exception ex) : base(ex) {} /// /// Initializes a new instance of the exception with serialized data. /// /// Holds the serialized object data about the exception being thrown. /// Contains contextual information about the source or destination. protected SystemException(SerializationInfo info, StreamingContext context) : base(info, context) {} } /// /// Base class for Slice user exceptions. /// [Serializable] public abstract class UserException : Exception { /// /// Creates a default-initialized user exception. /// public UserException() {} /// /// Creates a default-initialized user exception and sets the InnerException /// property to the passed exception. /// /// The inner exception. public UserException(System.Exception ex) : base(ex) {} /// /// Initializes a new instance of the exception with serialized data. /// /// Holds the serialized object data about the exception being thrown. /// Contains contextual information about the source or destination. protected UserException(SerializationInfo info, StreamingContext context) : base(info, context) {} public virtual void iceWrite(OutputStream ostr) { ostr.startException(null); iceWriteImpl(ostr); ostr.endException(); } public virtual void iceRead(InputStream istr) { istr.startException(); iceReadImpl(istr); istr.endException(false); } public virtual bool iceUsesClasses() { return false; } protected abstract void iceWriteImpl(OutputStream ostr); protected abstract void iceReadImpl(InputStream istr); } } namespace IceInternal { public class RetryException : Exception { public RetryException(Ice.LocalException ex) { _ex = ex; } public Ice.LocalException get() { return _ex; } private Ice.LocalException _ex; } }