|
844 | 844 | "o" |
845 | 845 | ] |
846 | 846 | }, |
| 847 | + { |
| 848 | + "cell_type": "markdown", |
| 849 | + "metadata": {}, |
| 850 | + "source": [ |
| 851 | + "This is how IPython formats exceptions internally:" |
| 852 | + ] |
| 853 | + }, |
| 854 | + { |
| 855 | + "cell_type": "code", |
| 856 | + "execution_count": null, |
| 857 | + "metadata": {}, |
| 858 | + "outputs": [], |
| 859 | + "source": [ |
| 860 | + "from IPython.core.ultratb import VerboseTB\n", |
| 861 | + "formatter = VerboseTB(color_scheme='Linux')" |
| 862 | + ] |
| 863 | + }, |
| 864 | + { |
| 865 | + "cell_type": "code", |
| 866 | + "execution_count": null, |
| 867 | + "metadata": {}, |
| 868 | + "outputs": [ |
| 869 | + { |
| 870 | + "name": "stdout", |
| 871 | + "output_type": "stream", |
| 872 | + "text": [ |
| 873 | + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n", |
| 874 | + "\u001b[1;31mRecursionError\u001b[0m Traceback (most recent call last)\n", |
| 875 | + "Cell \u001b[1;32mIn[31], line 1\u001b[0m\n", |
| 876 | + "\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m: f()\n", |
| 877 | + "\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n", |
| 878 | + "\u001b[0;32m 3\u001b[0m ex \u001b[38;5;241m=\u001b[39m e\n", |
| 879 | + "\n", |
| 880 | + "Cell \u001b[1;32mIn[19], line 4\u001b[0m, in \u001b[0;36mf\u001b[1;34m()\u001b[0m\n", |
| 881 | + "\u001b[1;32m----> 4\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mf\u001b[39m(): \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mf\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", |
| 882 | + "\n", |
| 883 | + "Cell \u001b[1;32mIn[19], line 4\u001b[0m, in \u001b[0;36mf\u001b[1;34m()\u001b[0m\n", |
| 884 | + "\u001b[1;32m----> 4\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mf\u001b[39m(): \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mf\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", |
| 885 | + "\n", |
| 886 | + " \u001b[1;31m[... skipping similar frames: f at line 4 (2974 times)]\u001b[0m\n", |
| 887 | + "\n", |
| 888 | + "Cell \u001b[1;32mIn[19], line 4\u001b[0m, in \u001b[0;36mf\u001b[1;34m()\u001b[0m\n", |
| 889 | + "\u001b[1;32m----> 4\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mf\u001b[39m(): \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mf\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", |
| 890 | + "\n", |
| 891 | + "\u001b[1;31mRecursionError\u001b[0m: maximum recursion depth exceeded\n" |
| 892 | + ] |
| 893 | + } |
| 894 | + ], |
| 895 | + "source": [ |
| 896 | + "try: f()\n", |
| 897 | + "except Exception as e:\n", |
| 898 | + " ex = e\n", |
| 899 | + " print(formatter.text(type(e), e, e.__traceback__))" |
| 900 | + ] |
| 901 | + }, |
847 | 902 | { |
848 | 903 | "cell_type": "code", |
849 | 904 | "execution_count": null, |
|
992 | 1047 | " if d := _g('image/svg+xml'): return d\n", |
993 | 1048 | " \n", |
994 | 1049 | " return ''\n", |
995 | | - " \n", |
| 1050 | + "\n", |
996 | 1051 | " return '\\n'.join(map(render_output, outputs))" |
997 | 1052 | ] |
998 | 1053 | }, |
|
0 commit comments