SPSecurity.CatchAccessDeniedException is different from SPSite.CatchAccessDeniedException, SPSite.CatchAccessDeniedException is reserved for internal use and is not intended to be used directly from your code.
bool originalCatchValue = SPSecurity.CatchAccessDeniedException;
SPSecurity.CatchAccessDeniedException = false;
try
{
//Your custom code here
//If a user does not have permission, exception will be thrown
//If CatchAccessDeniedException is true, then the user will be
//redirected to _layouts/AccessDenied.aspx page
}
catch(Exception ex)
{
//Your custom error message can be shown here
}
finally
{
//don't forget to reset the flag to original value
SPSecurity.CatchAccessDeniedException = originalCatchValue;
}