Skip to content

Instantly share code, notes, and snippets.

@MishraKhushbu
Created January 29, 2018 06:25
Show Gist options
  • Save MishraKhushbu/5c5c712bf147d2fee781513952de67f6 to your computer and use it in GitHub Desktop.
Save MishraKhushbu/5c5c712bf147d2fee781513952de67f6 to your computer and use it in GitHub Desktop.
Exception handling 29 Jan 2018
What is Exception?
An exception is an error that happens during execution of a program. When that
error occurs, Python generate an exception that can be handled, which avoids your
program to crash.
Why use Exception?
Exceptions are convenient in many ways for handling errors and special conditions
in a program. When you think that you have a code which can produce an error then
you can use exception handling
Raising an exception breaks current code execution and returns the exception
back until it is handled.
Some common Exceptions:
IOError
If the file cannot be opened.
ImportError
If python cannot find the module
ValueError
Raised when a built-in operation or function receives an argument that has the
right type but an inappropriate value
KeyboardInterrupt
Raised when the user hits the interrupt key (normally Control-C or Delete)
EOFError
Raised when one of the built-in functions (input() or raw_input()) hits an
end-of-file condition (EOF) without reading any data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment