summaryrefslogtreecommitdiffstats
path: root/tests/bugs/HandlerSig.java
blob: 8e644815f073359480441044d77ae5800646bdef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import org.aspectj.testing.Tester;

import org.aspectj.lang.reflect.*;

public class HandlerSig {

	public void doSomething() {
		// Get around "unreachable code error...
		if (true)
		{
			throw new BusinessException("Surprise!!");
		}
		System.out.println("Busy doing something.");
	}

	public static void main(String[] args) {
		try {
			HandlerSig m = new HandlerSig();
			m.doSomething();
		} catch (BusinessException be) {
			Tester.checkEqual(be.getMessage(), "Surprise!!");
		}
	}
}

class BusinessException extends RuntimeException {
	BusinessException(String message) {
		super(message);
	}
}

aspect AppMonitor {
	pointcut problemHandling() : handler(Throwable+);

	before() : problemHandling() {
		CatchClauseSignature cSig =
			(CatchClauseSignature) thisJoinPointStaticPart.getSignature();

		Tester.checkEqual(cSig.getParameterType(), BusinessException.class);
		Tester.checkEqual(cSig.getParameterName(), "be");
	}
}