Exemplo n.º 1
0
 //@SetteIncludeCoverage(classes = { B6a_CheckedExceptions.class }, methods = { "calledFunction(int, int)" })
 public static int tryCatch(int x, int y)
 {
     try
     {
         return(B6a_CheckedExceptions.calledFunction(x, y));
     }
     catch (Exception)
     {
         throw new MyException();
     }
 }
Exemplo n.º 2
0
        //@SetteIncludeCoverage(classes = { B6a_CheckedExceptions.class }, methods = { "calledFunction(int, int)" })
        public static int tryCatchFinally(int x, int y, int z)
        {
            int returnValue = 0;

            try
            {
                return(B6a_CheckedExceptions.calledFunction(x, y));
            }
            catch (Exception)
            {
                throw new MyException();
            }
            finally
            {
                // note: return statements in the finally block is not advised
                // - it overwrites the original return value
                // - it absorbs the thrown exception

                // In C# return statement not possible
                if (z > 0)
                {
                    returnValue = -1;
                }
                else if (z < 0)
                {
                    returnValue = -2;
                }

                // return statement in the finally block causes compile error
            }

            // this is intended, even if it is unreachable
#pragma warning disable
            return(returnValue);

#pragma warning enable
        }