title: Multiple tests with multiple throws
body: <p>I would like to create a method that will test different things and <strong>throw an error depending on the issue</strong> (and then exit the program).
  I am not really familiar with throwing exception... Is this method a good way to program it?</p>
  
  <pre><code>private static void testConnexions() throws IOException, Exception {
  
      File file = null;
      Socket socket;
  
      try {
          // Test access to the repository:
          file = new File(pdfRepository);
          if (!file.canRead())
              throw new SecurityException();
          if (!file.canWrite())
              throw new SecurityException();
          if (!file.exists())
              throw new SecurityException();
          if (!file.isDirectory())
              throw new SecurityException();
  
          // Connection to  Filenet:      
          connexion = new FilenetConnexion(filenetURI, objectStoreName,
                  stanza, dossierRacine, userName, password);
          connexion.connect();
  
          // Connection to a socket:
          socket = new Socket(serveurCV, portCV);
  
          // Initialize the JavaMail Session:
          Properties props = System.getProperties();
          if (serveurSMTP != null)
              props.put("mail.smtp.host", serveurSMTP);
          Session session = Session.getInstance(props, null);
  
  } catch (SecurityException e) {
      e.getMessage();
      e.printStackTrace();
  } catch (UnknownHostException e) {
      e.getMessage();
      e.printStackTrace();
  } catch (IOException e) {
      e.getMessage();
      e.printStackTrace();
  } catch (Exception e) {
      e.getMessage();
      e.printStackTrace();
  } 
  }
  </code></pre>
  
  <p>I would like to catch a message detailed enough to know if the repository can't be written in, or if the System.getProperties() got an error, etc.</p>
  
  <p>Thank you in advance for your help!</p>
  
  <p><strong>EDIT:</strong>
  Here is the solution I chose among all your contributions, hoping it can help someone:</p>
  
  <pre><code>private static void testConnexions() {
  
          File file = null;
          Socket socket;
  
          // Test access to the repository:
          try {
              file = new File(pdfRepository);
              if (!file.canRead())
                  throw new SecurityException(pdfRepository + " can't be read.");
              if (!file.canWrite())
                  throw new SecurityException(pdfRepository + " can't be written.");
              if (!file.exists())
                  throw new SecurityException(pdfRepository + " doesn't exist.");
              if (!file.isDirectory())
                  throw new SecurityException(pdfRepository + " isn't a folder.");    
          } catch (SecurityException e) {
              logger.error(e.getMessage());
              System.exit(1);
          }
  
          // Connection to  FileNet       
          try {
              connexion = new FilenetConnexion(filenetURI, objectStoreName,
                      stanza, dossierRacine, userName, password);
              connexion.connect();
          } catch (Exception e) {
              logger.error("Impossible to connect to FileNet. " + e.getMessage());
              System.exit(2);
          }
  
          // Connection to FrontalSocket
          try {
              socket = new Socket(serveurCV, portCV);
          } catch (UnknownHostException e) {
              logger.error("Impossible to connect to FrontalSocket. " + e.getMessage());
              System.exit(3);
          } catch (IOException e) {
              logger.error("Impossible to connect to FrontalSocket. " + e.getMessage());
              System.exit(3);
          }
  
          // Initialize the JavaMail session
          try {
              Properties props = System.getProperties();
              if (serveurSMTP != null)
                  props.put("mail.smtp.host", serveurSMTP);
              else{
                  logger.error("The SMTP host name is null");
                  System.exit(4);
              }
              Session session = Session.getInstance(props, null);
          } catch (Exception e) {
              logger.error("Impossible to connect to SMTP server. " + e.getMessage());
              System.exit(4);
          }
      }
  </code></pre>