в чем ошибка, вообще понять не могу?

выходит ошибка Error:(40, 23) java: exception org.telegram.telegrambots.meta.exceptions.TelegramApiException is never thrown in body of corresponding try statement

@Component
public class TelegramBot extends TelegramLongPollingBot {
    final BotConfig config;

    public TelegramBot(BotConfig config){
        this.config = config;
    }

    @Override
    public String getBotUsername() {
        return config.getBotName();
    }

    @Override
    public String getBotToken() {
        return config.getToken();
    }

    @Override
    public void onUpdateReceived(Update update) {

        if (update.hasMessage() && update.getMessage().hasText()){
            String massageText = update.getMessage().getText();
            long chatId = update.getMessage().getChatId();

            switch (massageText){
                case "/start":
                    try {
                        startCommandReceived(chatId,update.getMessage().getChat().getFirstName());
                    } catch (TelegramApiException e) { // Подчеркивает что тут
                        throw new RuntimeException(e);
                    }

            }
        }




    }
    private void startCommandReceived (long chatId, String name) {


        String answer = " Привет, " + name +" ты лучший ! ";

        sendMessage(chatId, answer);

    }

    private void sendMessage(long chatId, String textToSend){
        SendMessage message = new SendMessage();
        message.setChatId(String.valueOf(chatId));
        message.setText(textToSend);

        try {
            execute(message);
        }
        catch (TelegramApiException e){
            

        }
    }
}

Ответы (1 шт):

Автор решения: Ramiz

вот примерно то что описали коллеги в комментах. трудность в понимании скорее всего заключалась в том что т.н. checked exceptions - это фича редко встречаемая в других языках кроме Java. Именно поэтому Clean Code не рекомендует их использовать, но если они уже есть в API то надо уметь с ними работать (catch или throws). см также https://docs.oracle.com/javase/tutorial/essential/exceptions/index.html

@Component
public class TelegramBot extends TelegramLongPollingBot {
    final BotConfig config;

    public TelegramBot(BotConfig config){
        this.config = config;
    }

    @Override
    public String getBotUsername() {
        return config.getBotName();
    }

    @Override
    public String getBotToken() {
        return config.getToken();
    }

    @Override
    public void onUpdateReceived(Update update) {
        if (update.hasMessage() && update.getMessage().hasText()) {
            String massageText = update.getMessage().getText();
            long chatId = update.getMessage().getChatId();

            switch (massageText) {
                case "/start":
                    try {
                        startCommandReceived(chatId,update.getMessage().getChat().getFirstName());
                    } catch (TelegramApiException e) { // Подчеркивает что тут
                        throw new RuntimeException(e);
                    }
                break;
            }
        }
    }

    private void startCommandReceived(long chatId, String name) throws TelegramApiException {
        String answer = " Привет, " + name + " ты лучший ! ";
        sendMessage(chatId, answer);
    }

    private void sendMessage(long chatId, String textToSend) throws TelegramApiException {
        SendMessage message = new SendMessage();
        message.setChatId(String.valueOf(chatId));
        message.setText(textToSend);
        execute(message);
    }
}
→ Ссылка