Inheriting from Exception to provide your own Exception class would work fine for exceptions you generate in your code, and you could use the inner exception constructor to carry built in exceptions up the chain If you were goig to try that, you'd need to replace all of your exception handling code, and probably add a chunk more as well. I don't think it'd be substantially better than Peter McGrattan's approach, but it might allow you different options when preserving & examining the original exceptions and re-throwing, for example keeping a record of whether it has already been logged lower down the chain Just to be explicit, it is possible to use: catch (Exception e) { log(e); throw; } which will rethrow the original exception.
Inheriting from Exception to provide your own Exception class would work fine for exceptions you generate in your code, and you could use the inner exception constructor to carry built in exceptions up the chain. If you were goig to try that, you'd need to replace all of your exception handling code, and probably add a chunk more as well. I don't think it'd be substantially better than Peter McGrattan's approach, but it might allow you different options when preserving & examining the original exceptions and re-throwing, for example keeping a record of whether it has already been logged lower down the chain.
Just to be explicit, it is possible to use: catch (Exception e) { log(e); throw; } which will rethrow the original exception.
Starting from Windows XP you can get notified about every raised exception, even before it's known to be handled or not. This is available via so-called "vectored" exception handling, which is actually a little addition to the standard structured exception handling. Call AddVectoredExceptionHandler to add your own handler.
You'll get called right after the exception is raised, either by explicit throw/__CxxThrowException/RaiseException or implicitly by the processor (access violation or etc. ) You can log the exception in your handler (produce stack dump for instance), and return EXCEPTION_CONTINUE_SEARCH.
Msdn.microsoft. Com/en-us/library/ms681420(VS.85). Aspx is the base msdn article for that.
Examples aren't given for c# and from looking at it I suspect it's non-trivial. – penguat May 6 '10 at 11:29 it will be so nice if you'll give an example :) – andySF May 6 '10 at 11:38.
No, thats not possible. The only way this would be possible is using the debugging APIs (the managed version is named mdbg).
Sounds like you've got the Unhandled Exceptions as covered as possible, for handled exceptions can't you just eventually... catch (Exception e) {} and call the same logging function with the instance. If not and you really must have some instances where you have a catch but without catching an instance you can use... catch { throw; } to re-throw the exception to be eventually caught and logged as an un-handled exception.
It's a really big application and I will need to put the log.write() in all try catch blocks and that is what I wanted to avoid. Thank you – andySF May 6 '10 at 10:49.
C++ allows for catch(...) which catches all exceptions but doesn't really allow to analyze them in depth. (see stackoverflow.com/questions/2183113/usin... ) I'm not sure if it will work in C# though.
There's no way to catch an already caught exception except, may be, working with AddVectoredExceptionHandler. Having said that, you can use a catch-and-rethrow approach: catch(Exception e) { Logger. Log(e); throw; } or catch(Exception e) { bool rethrow = LoggerStrategy.
Log(e); if(rethrow) { throw; } } Better still, use the Logging Application Block.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.