What is an exception?



This exercise mentions an exception, what is that?


If something is an error, it should not be handled by your program in a way that allows the user to continue using the program, as it can cause unexpected behavior and issues. They should be fixed!

An exception, on the other hand, is something that you might want to allow your program to handle. Later you’ll come across something called catching exceptions, and that’s what this means. Exceptions typically don’t cause your program to behave in unexpected ways if they occur, so long as you handle them properly.

FAQ: Learn Python - Python Syntax - Handling Errors

Hi, i still cant not fully understand the concept of exceptions. can i get a more simpler explanation? thanks


For example:

get_user_input = raw_input("enter an integer: ")
trying_convert = int(get_user_input)

we ask the user for a integer by prompting for input with raw_input. But raw_input stores the result as string, so we need to convert to integer.

If the users enters 5, converting to integer goes fine. But if the enters hello, python will raise an error, given this can’t be converted to integer

The error raised by python will exit the program

If we then want to give the user another chance of entering input, we will first need to make an exception for the error so our program can continue running


another change, or another chance?