Exemplo n.º 1
0
        /// <summary>Creates a message using a error message template and arguments.</summary>
        /// <remarks>
        /// Creates a message using a error message template and arguments.
        /// <p>
        /// The template must be in JDK <code>MessageFormat</code> syntax
        /// (using {#} positional parameters).
        /// </remarks>
        /// <param name="error">error code, to get the template from.</param>
        /// <param name="args">arguments to use for creating the message.</param>
        /// <returns>the resolved error message.</returns>
        private static string Format(XException.ERROR error, params object[] args)
        {
            string template = error.GetTemplate();

            if (template == null)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < args.Length; i++)
                {
                    sb.Append(" {").Append(i).Append("}");
                }
                template = Sharpen.Runtime.DeleteCharAt(sb, 0).ToString();
            }
            return(error + ": " + MessageFormat.Format(template, args));
        }
Exemplo n.º 2
0
 /// <summary>Creates an XException using the specified error code.</summary>
 /// <remarks>
 /// Creates an XException using the specified error code. The exception
 /// message is resolved using the error code template and the passed
 /// parameters.
 /// </remarks>
 /// <param name="error">error code for the XException.</param>
 /// <param name="params">
 /// parameters to use when creating the error message
 /// with the error code template.
 /// </param>
 public XException(XException.ERROR error, params object[] @params)
     : this(Check.NotNull(error, "error"), Format(error, @params), GetCause(@params))
 {
 }
Exemplo n.º 3
0
 /// <summary>Constructor for sub-classes.</summary>
 /// <param name="error">error code for the XException.</param>
 /// <param name="params">
 /// parameters to use when creating the error message
 /// with the error code template.
 /// </param>
 protected internal ServerException(XException.ERROR error, params object[] @params
                                    )
     : base(error, @params)
 {
 }
Exemplo n.º 4
0
 /// <summary>Private constructor used by the public constructors.</summary>
 /// <param name="error">error code.</param>
 /// <param name="message">error message.</param>
 /// <param name="cause">exception cause if any.</param>
 private XException(XException.ERROR error, string message, Exception cause)
     : base(message, cause)
 {
     this.error = error;
 }
Exemplo n.º 5
0
 /// <summary>Creates an service exception using the specified error code.</summary>
 /// <remarks>
 /// Creates an service exception using the specified error code.
 /// The exception message is resolved using the error code template
 /// and the passed parameters.
 /// </remarks>
 /// <param name="error">error code for the XException.</param>
 /// <param name="params">
 /// parameters to use when creating the error message
 /// with the error code template.
 /// </param>
 public ServiceException(XException.ERROR error, params object[] @params)
     : base(error, @params)
 {
 }