Thursday, August 30, 2007

Re-throwing exceptions

When you want to pass your catched exception to higher level of exception-handling mechanism don't do something like


catch(Exception e){
Trace.WriteLine("{Message}");
throw new Exception("{Message}", e);
}


instead of this use the following construct, which will pass your exception to higher level:


catch(Exception e){
Trace.WriteLine("{Message}");
throw;
}

Wednesday, August 29, 2007

Calling methods from base class in Java

Don't forget that you can call method from the base class when you are overriding this method in derrived class! Simply use "super" operator for this purpose.


public AuthToken createAuthToken(HttpServletRequest request, HttpServletResponse response) throws UnauthorizedException{
...
//calling method from base class
return super.createAuthToken(request, response);
}