The reason for the failure is that when you press Cancel the SelectFaces() Sub returns, but has not set the 'selectedObjects' array to anything.
Maybe you should change the SelectFaces Sub to a function and return the result of calling ui.SelectionManager.SelectObjects(). Then the Main() Sub could exit without trying to use the 'selectedObjects' array if Cancel was clicked.
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX220.127.116.11 MP11 64bit Testing: NX18.104.22.168