If any exception other than a NoSuchZipFileException occurs, then display "An error occurred. Please check the entered data."
package com.codegym.task.task31.task3110;
import com.codegym.task.task31.task3110.command.ExitCommand;
import com.codegym.task.task31.task3110.exception.NoSuchZipFileException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Archiver
{
public static void main(String[] args) throws Exception
{
Operation operation = null;
do
{
try {
operation = askOperation();
CommandExecutor.execute(operation);
}
catch (Exception e)
{
if (e instanceof NoSuchZipFileException)
{
ConsoleHelper.writeMessage("You didn't select an archive or you selected an invalid file.");
} else
{
ConsoleHelper.writeMessage("An error occurred. Please check the entered data.");
}
}
}while(operation != Operation.EXIT);
}
public static Operation askOperation() throws IOException
{
Operation operation = null;
ConsoleHelper.writeMessage("Select an operation:0 - Zip files into an archive");
ConsoleHelper.writeMessage("1 - Add a file to an archive");
ConsoleHelper.writeMessage("2 - Remove a file from an archive");
ConsoleHelper.writeMessage("3 - Extract an archive");
ConsoleHelper.writeMessage("4 - View the contents of an archive");
ConsoleHelper.writeMessage("5 - Exit");
int ordinal = ConsoleHelper.readInt();
switch (ordinal)
{
case 0:
operation = Operation.CREATE;
break;
case 1:
operation = Operation.ADD;
break;
case 2:
operation = Operation.REMOVE;
break;
case 3:
operation = Operation.EXTRACT;
break;
case 4:
operation = Operation.CONTENT;
break;
case 5:
operation = Operation.EXIT;
break;
}
return operation;
}
}