ComponentPro UltimateTerminal

      Handling Exceptions

      Language Filter: AllSend comments on this topic to ComponentPro

      Exceptions thrown by the component and its dependencies can be easily caught by using try catch block. The table below lists all exceptions that can be caught when using the component: 

      Exception Description
      UltimateLicenseException The exception that is thrown when an error occurs while checking the license.
      SecureShellException The exception that is thrown when an SSH error occurs.
      ProxySocketException The exception that is thrown when a proxy error or socket error occurs.
      TerminalException The exception that is thrown when a terminal error occurs.


      The example below shows how to handle exceptions:

      using System;
      using ComponentPro.Net;
      using ComponentPro.Net.Terminal;
      // Create an SshClient object.
      SshClient client = new SshClient();
          // Connect to the specified server. 
          // Authenticate. 
          client.Authenticate("user", "password");
          client.Timeout = 25000;
          // Create a shell object in auto-processing mode. 
          TerminalShell shell = client.CreateShell(true);
          while (shell.IsConnected)
              Console.Write("Command: ");
              // Read the command to execute. 
              string command = Console.ReadLine();
              // Send the command to the SSH server. 
              // You can do something here. 
              // ... 
              // Get the response of the command. 
              string response = shell.ReadToEnd();
              // Print out the response. 
      catch (SecureShellException se)
          Console.WriteLine("\nAn SSH exception occurred: {0}", se.Message);
      catch (TerminalException te)
          Console.WriteLine("\nA terminal exception occurred: {0}", te.Message);
          // Close the connection.