示例#1
0
        /// <summary>
        /// Creates a catch block for the try block (no variable and catches all <typeparamref name="TException"/>s).
        /// </summary>
        /// <typeparam name="TException">The type of the <see cref="Exception"/> to catch.</typeparam>
        /// <returns>The catch's <see cref="Block&lt;TParent&gt;"/> to begin inserting statements.</returns>
        public Block <Try <TParent> > Catch <TException>() where TException : Exception
        {
            Block <Try <TParent> > catchBody;

            this.lstCatchBlocks.Add(CatchBlockWrapper <Try <TParent> > .Create(this, typeof(TException), null, out catchBody));

            return(catchBody);
        }
示例#2
0
        /// <summary>
        /// Creates a catch block for the try block (with a variable and catches all <typeparamref name="TException"/>s).
        /// </summary>
        /// <typeparam name="TException">The type of the <see cref="Exception"/> to catch.</typeparam>
        /// <param name="variableName">The variable name of the caught exception.</param>
        /// <returns>The catch's <see cref="Block&lt;TParent&gt;"/> to begin inserting statements.</returns>
        /// <exception cref="ArgumentException">
        ///		<para>When the <paramref name="variableName"/> is a name that is null, empty, or whitespace, the exception is thrown.</para>
        ///		<para>- Or -</para>
        ///		<para>When the <paramref name="variableName"/> is a name that is already declared, the exception is thrown.</para>
        ///	</exception>
        public Block <Try <TParent> > Catch <TException>(string variableName) where TException : Exception
        {
            Block <Try <TParent> > catchBody;

            if (string.IsNullOrWhiteSpace(variableName))
            {
                throw new ArgumentException("The variable name cannot be null, empty, or whitespace.", "variableName");
            }

            variableName = variableName.Trim();

            if (this.GetVariablesInScope().Any(x => x.Name == variableName))
            {
                throw new ArgumentException(string.Format("Variable, {0}, is already declared.  Please assign a different name.", variableName));
            }

            this.lstCatchBlocks.Add(CatchBlockWrapper <Try <TParent> > .Create(this, typeof(TException), variableName, out catchBody));

            return(catchBody);
        }