Koen,
I don't quite understand what are you trying to accomplish.
Are you trying to force programmers using this method to put it in a
try/catch or you want the compiler to generate this code for you. Either
ways I don't think you can do it via attributes.
What you can do though, is to add try/catch in your code.
for example:
class Foo
{
public Bar()
{
try
{
BarImp();
}
catch(System.Exception ex)
{
SaveToDb(ex);
throw ex;
}
}
private BarImp()
{
// method implementation.
}
}
The user see Bar method and calling it will log any exception if it happens.
Ofcourse you don't nee to split the implementaiton on Bar and BarImp both
can go in the same method.
Anyways I'd suggest to check out the logging frameworks that are out there
or look at the System.Diagnostics names space and find out how to use
listeners for implementing more flexible logging system.
--
Stoitcho Goutsev (100).
"Koen" <de******@gmail.com> wrote in message
news:11*********************@g10g2000cwb.googlegro ups.com...
Hi,
I have been reading a bit basic stuff about method attributes in C#,
and I wanted to build the following functionality with it:
if a method has the custom attribute <LogException> the method has to
be wrapped as follows:
try
{
// call method
}
catch(System.Exception ex)
{
SaveToDb(ex);
throw ex;
}
Can somebody help me on the way how to implement this kind of
functionality? I'm quite sure this is possible, since i assume the
microsoft exception framework uses the same technique.
Tnx for any help.
Regards,
Koen Appeltans