Friday, December 10, 2004

throw; vs throw e;

throw; is better choice than throw exception. {The stack trace is maintained in previous}

private void Test() {
    Test2();
}
private void Test2() {
try {
    Test3();
}
catch(Exception e){
    //some cleanup code
    throw;
    // throw e; //This will lose the stack trace.
}
}
private void Test3(){
    //some logic
    throw new Exception("abcd");
}

No comments: