Skip to content

Commit 309dd2b

Browse files
committed
gh-136722: TurtleGraphicsError documentation
1 parent 8ac7613 commit 309dd2b

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

Doc/library/turtle.rst

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,82 @@ Public classes
25232523
* ``a.rotate(angle)`` rotation
25242524

25252525

2526+
Exceptions
2527+
----------
2528+
2529+
2530+
.. exception:: TurtleGraphicsError
2531+
2532+
Exception raised when a turtle graphics operation fails.
2533+
2534+
This exception is raised in various error conditions, such as:
2535+
2536+
* Invalid color specifications (e.g., color values out of range)
2537+
* Invalid shape types or names
2538+
* Invalid turtle graphics modes
2539+
* Invalid canvas arguments
2540+
* Other turtle graphics configuration errors
2541+
2542+
Examples:
2543+
2544+
**Invalid color specifications:**
2545+
2546+
.. doctest::
2547+
:skipif: _tkinter is None
2548+
2549+
>>> screen.colormode(1.0)
2550+
>>> turtle.pencolor(240, 160, 80)
2551+
Traceback (most recent call last):
2552+
...
2553+
TurtleGraphicsError: bad color sequence: (240, 160, 80)
2554+
2555+
>>> turtle.pencolor("invalid_color_name")
2556+
Traceback (most recent call last):
2557+
...
2558+
TurtleGraphicsError: bad color string: invalid_color_name
2559+
2560+
**Invalid shape types:**
2561+
2562+
.. doctest::
2563+
:skipif: _tkinter is None
2564+
2565+
>>> from turtle import Shape
2566+
>>> s = Shape("invalid_type", None)
2567+
Traceback (most recent call last):
2568+
...
2569+
TurtleGraphicsError: There is no shape type invalid_type
2570+
2571+
**Invalid turtle graphics modes:**
2572+
2573+
.. doctest::
2574+
:skipif: _tkinter is None
2575+
2576+
>>> screen.mode("invalid_mode")
2577+
Traceback (most recent call last):
2578+
...
2579+
TurtleGraphicsError: No turtle-graphics-mode invalid_mode
2580+
2581+
**Invalid shape names:**
2582+
2583+
.. doctest::
2584+
:skipif: _tkinter is None
2585+
2586+
>>> turtle.shape("nonexistent_shape")
2587+
Traceback (most recent call last):
2588+
...
2589+
TurtleGraphicsError: There is no shape named nonexistent_shape
2590+
2591+
**Invalid shape parameters:**
2592+
2593+
.. doctest::
2594+
:skipif: _tkinter is None
2595+
2596+
>>> turtle.shapesize(stretch_wid=0, stretch_len=1)
2597+
Traceback (most recent call last):
2598+
...
2599+
TurtleGraphicsError: stretch_wid/stretch_len must not be zero
2600+
2601+
25262602
.. _turtle-explanation:
25272603

25282604
Explanation

0 commit comments

Comments
 (0)