aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/DeclaredExcs.java
diff options
context:
space:
mode:
authorwisberg <wisberg>2002-12-16 18:51:06 +0000
committerwisberg <wisberg>2002-12-16 18:51:06 +0000
commit144143c2970a1e874d74cdbd0f8c622d4282a3c3 (patch)
treeb12383d3d9e76c7e1f25f7fbec83051ef17f81fb /tests/new/DeclaredExcs.java
parentfafae443719b26159ab2d7dac1c9b46b5e00b671 (diff)
downloadaspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.tar.gz
aspectj-144143c2970a1e874d74cdbd0f8c622d4282a3c3.zip
initial version
Diffstat (limited to 'tests/new/DeclaredExcs.java')
-rw-r--r--tests/new/DeclaredExcs.java97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/new/DeclaredExcs.java b/tests/new/DeclaredExcs.java
new file mode 100644
index 000000000..21b1f1009
--- /dev/null
+++ b/tests/new/DeclaredExcs.java
@@ -0,0 +1,97 @@
+import org.aspectj.testing.Tester;
+
+public class DeclaredExcs {
+ public static void main(String[] args) { test(); }
+
+ public static void test() {
+ Foo foo = new Foo();
+
+ Tester.checkEqual(foo.foo(), "success", "foo()");
+ try {
+ foo.bar(false);
+ } catch (Exception e) {
+ Tester.check(false, "shouldn't catch");
+ }
+
+ try {
+ Bar bar = new Bar(false);
+ } catch (MyException e) {
+ Tester.check(false, "shouldn't catch");
+ }
+
+ try {
+ Bar bar = Bar.getNewBar(true);
+ Tester.check(false, "shouldn't get here");
+ } catch (MyException e) {
+ Tester.check(true, "should catch");
+ }
+ }
+}
+
+class Foo {
+ public void bar(boolean throwIt) throws Exception {
+ if (throwIt) {
+ throw new MyException("you asked for it");
+ }
+ }
+
+ public String foo() {
+ try {
+ bar(false);
+ } catch (Exception exc) {
+ Tester.check(false, "shouldn't catch anything");
+ }
+
+ try {
+ bar(true);
+ } catch (MyException exc) {
+ return "success";
+ } catch (Exception e1) {
+ return "failure";
+ }
+
+ return "failure";
+ }
+}
+
+class Bar {
+ String value;
+
+ public static Bar getNewBar(boolean throwIt) throws MyException {
+ return new Bar(throwIt);
+ }
+
+ public Bar(boolean throwIt) throws MyException {
+ if (throwIt) {
+ throw new MyException("you asked for it from constructor");
+ }
+ value = "boolean";
+ }
+
+ public Bar(String value) {
+ this.value = value;
+ }
+}
+
+
+class MyException extends Exception {
+ public MyException(String label) {
+ super(label);
+ }
+}
+
+aspect A {
+ before (): this(*) && execution(* *(..)) || execution(new(..)) {
+ //System.out.println("entering: "+thisJoinPoint);
+ }
+ after (): this(*) && execution(* *(..)) || execution(new(..)) {
+ //System.out.println("exiting: "+thisJoinPoint);
+ }
+
+ Object around(): this(*) && call(* *(..)) {
+ //System.out.println("start around: "+thisJoinPoint);
+ Object ret = proceed();
+ //System.out.println("end around: "+thisJoinPoint);
+ return ret;
+ }
+}