Programování v C++

Cíle cvičení

  • Demonstrace: Exceptions
  • Cvičení: Exceptions
  • Demonstrace: Visitor
  • Cvičení: Výrazy II

Demonstrace: Exceptions

  • Error handling
  • Keywords: throw, try, catch
  • catch(...) ~ bad idea?
  • stack unwinding
  • std::exception, custom exception
  • #include <stdexcept>
  • noexcept



class exception {
  public:
    // Prepare message in a ctor if possible.
    exception();
    // Return message.
    virtual const char *what() const;
};
  

Cvičení: Exceptions

Umístění: ./labs/08-exceptions/

Čas: 20 minutes

Vytvořte aplikaci, která čte celá čísla se standardního vstupu. Ošetřete selhání funkce std::stoi.

Definujte a použijte vlastní vyjimku. Například pokud uživatel zadá číslo větší než daná mez.

Demonstrace: Visitor

  • Visitor design pattern
  • forward declaration

Cvičení: Výrazy II

Umístění: ./labs/08-expressions/

Umístění: ReCodex

Rozšiřte svou implementaci aplikace pro správu výrazů.

Shrnutí

  • Demonstrace: Exceptions
  • Cvičení: Exceptions
  • Demonstrace: Visitor
  • Cvičení: Výrazy II