{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b7ba5bda",
   "metadata": {},
   "source": [
    "# 15-22 · Ошибки файловой системы\n",
    "\n",
    "Практика к разделу [«Ошибки файловой системы»](../../site/chapters/glava-15/15-22-oshibki-fajlovoj-sistemy.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "482c7c08",
   "metadata": {},
   "source": [
    "## Рабочий пример — FileNotFoundError"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "886f4992",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T15:53:05.180183Z",
     "iopub.status.busy": "2026-08-18T15:53:05.180054Z",
     "iopub.status.idle": "2026-08-18T15:53:05.200467Z",
     "shell.execute_reply": "2026-08-18T15:53:05.200005Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "from pathlib import Path\n",
    "\n",
    "not_found_caught = False\n",
    "try:\n",
    "    Path(\"net_takogo_fajla.txt\").read_text(encoding=\"utf-8\")\n",
    "except FileNotFoundError:\n",
    "    not_found_caught = True\n",
    "print(not_found_caught)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05bbe6d6",
   "metadata": {},
   "source": [
    "## Задание ★★ Самостоятельная задача — IsADirectoryError"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "973dc405",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T15:53:05.201594Z",
     "iopub.status.busy": "2026-08-18T15:53:05.201491Z",
     "iopub.status.idle": "2026-08-18T15:53:05.204155Z",
     "shell.execute_reply": "2026-08-18T15:53:05.203746Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "from pathlib import Path\n",
    "\n",
    "Path(\"papka_test\").mkdir(exist_ok=True)\n",
    "is_dir_error_caught = False\n",
    "try:\n",
    "    open(\"papka_test\", \"r\", encoding=\"utf-8\")\n",
    "except IsADirectoryError:\n",
    "    is_dir_error_caught = True\n",
    "print(is_dir_error_caught)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
