summaryrefslogtreecommitdiffstats
path: root/docs/sandbox/inoculated/src/MainFailure.java
diff options
context:
space:
mode:
authorwisberg <wisberg>2003-08-06 02:08:40 +0000
committerwisberg <wisberg>2003-08-06 02:08:40 +0000
commita63bc04fb1cb6e8d6d0bc2a509ab9658e3d78c43 (patch)
treecd4e827c60136df7bf9850591b0c64baff549d20 /docs/sandbox/inoculated/src/MainFailure.java
parentb0d37c4b51a344bee94bb7f7cc1ecef1a233e3ab (diff)
downloadaspectj-a63bc04fb1cb6e8d6d0bc2a509ab9658e3d78c43.tar.gz
aspectj-a63bc04fb1cb6e8d6d0bc2a509ab9658e3d78c43.zip
initial checkin of the sandbox.
The basic structure and examples of each type are there, but I have more examples and the ones there are not altogether validated. I'll make a few more changes before emailing dev and users about usage, etc.
Diffstat (limited to 'docs/sandbox/inoculated/src/MainFailure.java')
-rw-r--r--docs/sandbox/inoculated/src/MainFailure.java74
1 files changed, 74 insertions, 0 deletions
diff --git a/docs/sandbox/inoculated/src/MainFailure.java b/docs/sandbox/inoculated/src/MainFailure.java
new file mode 100644
index 000000000..6d5a62a35
--- /dev/null
+++ b/docs/sandbox/inoculated/src/MainFailure.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 1998-2002 PARC Inc. All rights reserved.
+ *
+ * Use and copying of this software and preparation of derivative works based
+ * upon this software are permitted. Any distribution of this software or
+ * derivative works must comply with all applicable United States export
+ * control laws.
+ *
+ * This software is made available AS IS, and PARC Inc. makes no
+ * warranty about the software, its performance or its conformity to any
+ * specification.
+ */
+
+import java.util.*;
+import java.io.*;
+import org.aspectj.lang.*;
+
+/** @author Wes Isberg */
+
+public aspect MainFailure {
+
+ public static void main (String[] args) { TargetClass.main(args); }
+
+ pointcut main(String[] args) :
+ args(args) && execution(public static void main(String[]));
+
+ // article page 42 - recording failures from main
+ // START-SAMPLE testing-inoculated-failureCapture Log failures
+ /** log after failure, but do not affect exception */
+ after(String[] args) throwing (Throwable t) : main(args) {
+ logFailureCase(args, t, thisJoinPoint);
+ }
+ // END-SAMPLE testing-inoculated-failureCapture
+
+ // alternate to swallow exception
+// /** log after failure and swallow exception */
+// Object around() : main(String[]) {
+// try {
+// return proceed();
+// } catch (Error e) { // ignore
+// logFailureCase(args, t, thisJoinPoint);
+// // can log here instead
+// }
+// return null;
+// }
+
+ public static void logFailureCase(String[] args, Throwable t, Object jp) {
+ System.err.println("failure case: args " + Arrays.asList(args));
+ }
+}
+
+class TargetClass {
+ static Thread thread;
+ /** will throw error if exactly one argument */
+ public static void main (String[] args) {
+ // make sure to do at least one failure
+ if (thread == null) {
+ Runnable r = new Runnable() {
+ public void run() {
+ main(new String[] {"throwError" });
+ }
+ };
+ thread = new Thread(r);
+ thread.start();
+ }
+ if (1 == args.length) {
+ throw new Error("hello");
+ }
+ try { thread.join(); }
+ catch (InterruptedException ie) { }
+ }
+}
+
+