Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Exceptions

Hello, 

i don't know if this will help you because i don't completely understand what is your problem. But try this

import java.io.IOException;
import org.aspectj.lang.SoftException;

public final class TestInputStream extends InputStream {

/* (non-Javadoc)
* @see java.io.InputStream#read()
*/
@Override
public int read(){
//code
return 0;
}

/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Should be 0: "+new TestInputStream().read());
}

}

import java.io.IOException;
//Will wrap an SofteningException INSIDE read
public final aspect SofteningTestAspect {
declare soft: IOException : call(int *.read());
}

import java.io.IOException;
import org.aspectj.lang.SoftException;

public final aspect TestInputAspect {


pointcut readingTest() : call(int TestInputStream.read());


int around() throws SoftException : readingTest() {
//here code! An change if
if(true)throw new SoftException(new IOException("Inside aspect!"));
return 0;
}

}

I just start working with aspects, hope it helps

Alejandro

On Mar 5, 2009, at 11:01 PM, Andrica Silviu wrote:

Hello,
 I was hoping you could help me with a problem I have:
I want to instrument calls to InputStream.read(). This method migtht throw an exception. The problem is that in the application I want to instrument contains a class that
implements InputStream but its read() method signature does not contain a throw declaration. Thus, the compilation fails.
I use an around advice which throws an IOException. If I declare the around advice without the throws clause, then the application does not work correctly.

Thanks in advance,
 Silviu
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Alejandro Garcia
Website: atelier.inf.unisi.ch





Back to the top