!--a11y-->
SAPClient Exceptions 
Errors in the .NET Connector are thrown as .NET exceptions. An exception is the preferred method to handle errors because exceptions are harder to ignore than are return codes. They also provide you detailed information to create more robust applications.
The SAP .NET Connector has the following exception classes:
· RfcCommunicationException
· RfcLogonException
· RfcSystemException
· RfcAbapException
· RfcException
· RfcMarshalException
Coding Recommendations for RFC Exceptions
We recommend you to have at least two catch blocks. The first catch statement is for SAP exceptions (specific) and the second for others (generic), for example errors from the runtime or other resources.
We recommend you to close the proxy connection in the finally programming block.
SAP .NET Connector closes connections eventually. However, to achieve better performance, we recommend you to close the connection in the finally clause of your class. We also recommend that you close any external resources such as open files or database connections here as well.
Instead of providing a status of the SAP RFC connection, we recommend that you simply invoke the method and deal with the exception. The SAP .NET Connector will maintain the status of the connection internally.

The Proxy.Connection.Open() method causes an RFC ping. This allows you to see if the system is up. Subsequent Proxy.Connection.open() methods will be ignored until there is a Connection.Close().
Example
|
try { // Call methods here proxy.Connection.Open(); proxy.Rfc_Function_Search(txtRFC.Text,"EN", ref tblRFC); } catch (RfcCommunicationException ex) { MessageBox.Show(ex.ToString()); return; } catch (RfcLogonException ex) { MessageBox.Show(ex.ToString()); return; } catch (RfcAbapException ex) { switch (ex.AbapException) { case (SAPProxy1.No_Function_Found): MessageBox.Show("no function found"); break; case(SAPProxy1.Nothing_Specified): MessageBox.Show("Nothing specified"); break; default: MessageBox.Show("Some unknown abap error occurred"); break; } //switch } catch (Exception ex) { MessageBox.Show(ex.ToString()); return; } finally {proxy.Connection.Close();} |