Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] (very newbie question) Logging exceptions

Thanks a lot Wes!

I wrote some test code. If I throw an Exception it is logged nicely.
If I cause a FileNotFoundException the aspect does not pick this up.
What am I missing?

		File file = new File("c:/tmp/non-existen.txt");
		
		try {
			FileInputStream fileInputStream = new FileInputStream(file);
		} catch (FileNotFoundException e) {

On 3/14/06, Wes Isberg <wes@xxxxxxxxxxxxxx> wrote:
> This prints the exception as it is thrown from any method-
> execution:
>
>   aspect A {
>     pointcut pc() : execution(* *(..));
>     after() throwing (Throwable t) : pc() {
>        t.printStackTrace();
>     }
>   }
>
> It will print the same exception for each
> dynamically-enclosing method, so you'd want to skip
> duplicates (and probably narrow the pointcut a bit).
>
> The AOP@Work article on library aspects has 31 ready-to use
> aspects.  Take a look at "ObserveThrown" or
> "ObserveThrownContext."
>   http://www-128.ibm.com/developerworks/java/library/j-aopwork14/
>
> Wes
>
>
>
> (And probably in many others - google?)
>
> Wes
>
>
> On Tue, 14 Mar 2006 13:09:06 +0100
>  "Kees de Kooter" <kdekooter@xxxxxxxxx> wrote:
> > This question has propably been posted a million times
> > before.
> > Unfortunately I cannot find a working solution anywhere.
> >
> > I want to get rid of all the log.error lines in my code,
> > so I want to
> > write an aspect that logs exceptions when they occur, or
> > when the
> > catch statement is entered and log the exception message
> > and the line
> > and class in which it occurred.
> >
> > --
> > Thanks,
> > Kees de Kooter
> > http://www.boplicity.net
> >
> >
> > --
> > Cheers,
> > Kees de Kooter
> > http://www.boplicity.nl
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top