Summary: | Feature request: User-specifiable exception in "declare soft" | ||
---|---|---|---|
Product: | [Tools] AspectJ | Reporter: | Ramnivas Laddad <ramnivas> |
Component: | Compiler | Assignee: | Jim Hugunin <jim-aj> |
Status: | REOPENED --- | QA Contact: | |
Severity: | enhancement | ||
Priority: | P5 | ||
Version: | 1.2 | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
Ramnivas Laddad
2003-10-20 14:17:59 EDT
I would like this even more if it were also possible to call a member function that returns a throwable or subtype thereof, which takes a single argument: the original exception. I use this idiom with abstract aspects and for polymorphic exception handling. E.g., aspect Conversion { declare soft: Exception : call(* model..*(..)) : convertException; ModelException convertException(Throwable cause) { throw new ModelException(cause); } } I know this proposal looks like C# delegates. However using a Java approach with worker objects would require exposing the cause as a special form. Maybe the 3rd part could be any Java expression and target could return the throwable, e.g., declare soft: Exception : call(* model..*(..)) : convertException(target); or declare soft: Exception : call(* model..*(..)) : new RuntimeException(target); This can be solved by always using declare soft according to a standard idiom where it must be paired with an around advice that does the actual change of the exception. This will increase the verbosity of the examples below, but only by a couple of lines. For Ron's example, you can change it to: aspect Conversion { pointcut soften(): call(* model..*(..)); declare soft: Exception: soften(); Object around(): soften() { try { return proceed(); } catch (Exception e) { throw new ModelException(cause); } } } This should probably be added to the FAQ. We can revist this later if there are a lot more programs out there using declare soft to drive the design. LATER/REMIND bugs are being automatically reopened as P5 because the LATER and REMIND resolutions are deprecated. |