You've got the right idea, but you must do your own verification. This is typically done using a try/catch block.
Please look up these methods in the documentation/help so that you can understand their requirements. For example, in order to use XDocument.Submit(), you must NOT disable submit in the toolbars. Here's a quote from the help files:
Using the Submit method is similar to, but not exactly like, using the submit operation from the InfoPath user interface. Calling the Submit method simply performs the submit operation, but the submit operation must first be enabled for a form in design mode.
Note You can write a custom submit operation using the OnSubmitRequest event, and then you can programmatically call the event using the Submit method.