Pygame Tutorial
Selected Reading
- Pygame - Discussion
- Pygame - Useful Resources
- Pygame - Quick Guide
- Pygame - Errors and Exception
- Pygame - PyOpenGL
- Pygame - The Sprite Module
- Pygame - Access CDROM
- Pygame - Load cursor
- Pygame - Using Camera module
- Pygame - Playing Movie
- Pygame - Playing music
- Pygame - Mixer channels
- Pygame - Sound objects
- Pygame - Transforming Images
- Pygame - Use Text as Buttons
- Pygame - Moving Rectangular objects
- Pygame - Moving with mouse
- Pygame - Moving with Numeric pad keys
- Pygame - Moving an image
- Pygame - Displaying Text in Window
- Pygame - Loading image
- Pygame - Drawing shapes
- Pygame - Mouse events
- Pygame - Keyboard events
- Pygame - Event objects
- Pygame - Color object
- Pygame - Locals module
- Pygame - Display modes
- Pygame - Hello World
- Pygame - Overview
- Pygame - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Pygame - Errors and Exception
Pygame - Errors and Exception
Top level pygame module defines pygame.error as a standard Pygame exception. This exception is raised whenever a pygame or SDL operation fails. You can catch any anticipated problems and deal with the error. The exception is always raised with a descriptive message about the problem.
>>> import pygame pygame 1.9.6 Hello from the pygame community. https://www.pygame.org/contribute.html >>> screen = pygame.display.set_mode((640, -1)) Traceback (most recent call last): File "<pyshell#1>", pne 1, in <module> screen = pygame.display.set_mode((640, -1)) pygame.error: Cannot set negative sized display mode
Being derived from the RuntimeError exception, which can also be used to catch these raised errors.
>>> try: screen = pygame.display.set_mode((640, -1)) except pygame.error as e: print ("unable to set display: ", e) unable to set display Cannot set: negative sized display mode
There are two more functions in this module to set and retrieve error message.
set_error(error_msg)
SDL maintains an internal error message. When pygame.error()standard pygame exception is raised, this string is used as error message.
It gets the current error message.
get_error()
It returns the string as error message of pygame.error() message.
Advertisements