I was working on a SharePoint Web Part to display listitems in a list that the user had access to.
I used the DoesUserHavePermission() function in the SPPermissionCollection class.
Soon I realized that the method had a bug.
It returned true if the user had permissions to the item and thats great, but when the user didnt had permissions to the item, it threw an AccessDeniedException.
To make this work i had to do two things:
1. the CatchAccessDeniedException property of the SPSites class must be set to false
2. catch the System.UnauthorizedAccessException