public static int tryCatch(int x, int y) { try { return(B6b_UncheckedExceptions.calledFunction(x, y)); } catch (Exception) { throw new Exception(); } }
private static int recursive_(int x, int depth) { if (depth >= 10) { throw new Exception(); } if (x % 100 == 0) { return(x); } else { return(B6b_UncheckedExceptions.recursive_(x - 1, depth + 1)); } }
public static int tryCatchFinally(int x, int y, int z) { int returnValue = 0; try { return(B6b_UncheckedExceptions.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 }