Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import org.aspectj.testing.Tester;
  2. public class TryCatchFinally {
  3. public static void main(String[] args) {
  4. Tester.checkEqual(m1(), "good");
  5. Tester.checkEqual(m2(), "good");
  6. Tester.checkEqual(m3(), "good");
  7. try {
  8. m1v();
  9. } catch (RuntimeException re) {
  10. Tester.event("main-caught");
  11. }
  12. Tester.checkAndClearEvents(new String[] {
  13. "caught", "finally", "main-caught"} );
  14. try {
  15. m2v();
  16. } catch (RuntimeException re) {
  17. Tester.event("main-caught");
  18. }
  19. Tester.checkAndClearEvents(new String[] {
  20. "caught", "finally", "main-caught"} );
  21. m3v();
  22. Tester.checkAndClearEvents(new String[] {
  23. "caught", "finally"} );
  24. }
  25. public static String m1() {
  26. try {
  27. throw new RuntimeException("hi");
  28. } catch (RuntimeException er) {
  29. throw er;
  30. } finally {
  31. return "good";
  32. }
  33. }
  34. public static String m2() {
  35. try {
  36. return m1() + "XXX";
  37. } catch (RuntimeException er) {
  38. throw er;
  39. } finally {
  40. return "good";
  41. }
  42. }
  43. public static String m3() {
  44. try {
  45. throw new RuntimeException("hi");
  46. } catch (RuntimeException er) {
  47. return "bad-c";
  48. } finally {
  49. return "good";
  50. }
  51. }
  52. public static void m1v() {
  53. try {
  54. throw new RuntimeException("hi");
  55. } catch (RuntimeException er) {
  56. Tester.event("caught");
  57. throw er;
  58. } finally {
  59. Tester.event("finally");
  60. }
  61. }
  62. public static void m2v() {
  63. try {
  64. throw new RuntimeException("hi");
  65. } catch (RuntimeException er) {
  66. Tester.event("caught");
  67. throw er;
  68. } finally {
  69. Tester.event("finally");
  70. }
  71. }
  72. public static void m3v() {
  73. try {
  74. throw new RuntimeException("hi");
  75. } catch (RuntimeException er) {
  76. Tester.event("caught");
  77. return;
  78. } finally {
  79. Tester.event("finally");
  80. }
  81. }
  82. }