Skip to content

Instantly share code, notes, and snippets.

@AseiSugiyama
Created May 18, 2019 08:00
Show Gist options
  • Save AseiSugiyama/4219c4b61cda2d76f4dc6ddd39bb5af0 to your computer and use it in GitHub Desktop.
Save AseiSugiyama/4219c4b61cda2d76f4dc6ddd39bb5af0 to your computer and use it in GitHub Desktop.
Untitled5.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Untitled5.ipynb",
"version": "0.3.2",
"provenance": [],
"collapsed_sections": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/AseiSugiyama/4219c4b61cda2d76f4dc6ddd39bb5af0/untitled5.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "wQ_I2uRO7FQ4",
"colab_type": "code",
"colab": {}
},
"source": [
"def raise_exception():\n",
" raise RecursionError()\n",
" \n",
"def test_exception_return(exception_raiser):\n",
" try:\n",
" exception_raiser()\n",
" except RecursionError:\n",
" return False\n",
" "
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "jaRAmfMt7cTH",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "d3d83f9f-a6d5-4250-f787-405335309acc"
},
"source": [
"print(test_exception_return(exception_raiser))"
],
"execution_count": 11,
"outputs": [
{
"output_type": "stream",
"text": [
"False\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "A7i0_Uf37mr7",
"colab_type": "code",
"colab": {}
},
"source": [
"def raise_recursion_exception():\n",
" return raise_recursion_exception()"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "1ujzJnPK8WUn",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 294
},
"outputId": "625f8bcf-384b-4ca0-fb1c-2b3c2f369f5d"
},
"source": [
"raise_recursion_exception()"
],
"execution_count": 13,
"outputs": [
{
"output_type": "error",
"ename": "RecursionError",
"evalue": "ignored",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mRecursionError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-13-f4a1ee3e8474>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mraise_recursion_exception\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m<ipython-input-12-240c9942d670>\u001b[0m in \u001b[0;36mraise_recursion_exception\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mraise_recursion_exception\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mraise_recursion_exception\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"... last 1 frames repeated, from the frame below ...\n",
"\u001b[0;32m<ipython-input-12-240c9942d670>\u001b[0m in \u001b[0;36mraise_recursion_exception\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mraise_recursion_exception\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mraise_recursion_exception\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mRecursionError\u001b[0m: maximum recursion depth exceeded"
]
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "ujxJ6WMA8nYj",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "31c7aa45-d1f8-4aef-96f1-8c74ef90cc80"
},
"source": [
"test_exception_return(raise_recursion_exception)"
],
"execution_count": 9,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"False"
]
},
"metadata": {
"tags": []
},
"execution_count": 9
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "R8vOK5yF8394",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": 0,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment