// Method to saveAsFile(). private void saveAsFile() { // Set a file. fileName = FileIO.nameFile(this); // If a file name is selected. if (fileName != null) { // Try block to throw a custom exception. try { // Save file. FileIO.saveFile(this, fileName, sender.getText()); } // End of try to get message. catch (BufferEmptyException e) // Catch InvalidFileReference. { // Capture the stack trace into a String. setExceptionString(e.fillInStackTrace()); // Pass message to the JOptionPane manager. setExceptionPane( "There is nothing in the sender panel to write.\n\n" + "Do you want to see the stack trace?"); } // End of catch on BufferEmptyException. } // End of if a fileName is selected. } // End of saveAsFile() method.