check for invalid handle value correctly