exception handling Flashcards

1
Q

is used to handle exceptions (errors) that may
arise during the execution of a program.

A

try — except block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

types of try except block

A
  1. try-except
  2. except block
  3. catching all exception
  4. else with try except
  5. finally block
  6. raising exception
  7. custom exception
  8. exception chaining
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

is used to wrap the code that might throw an exception so if any error occurs with the try an error the python will immediately jump the correspond except block to handle that error.

A

try-except

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

is executed if an error occurs in the try block so you can specify the type of exception that you want to catch

A

except block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

is you can catch all exceptions with a generic block by omitting the specific exception name. however, this should be used carefully since it can also catch unexpected errors making the debugging harder

A

catching all exceptions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

else block can be used in conjunction with try-except code that could run only if no exception or raise

A

else with try - except

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

is used to execute code that should run no matter what whether an exception occurred or not it is often used to clean up operations like closing files or network connection

A

finally block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

you can manually raise an exception in Python using the raise keyword. this is useful when you want to trigger an exception based on a specific condition okay specific condition

A

raising exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

you can Define your own exception types by creating a new class that inherits from the built-in exception class so this is useful for creating specific types of error in our programs

A

custom exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

python allows you to chain exceptions using the race from syntax which help in providing more context when one exception leads to another

A

exception chaining

How well did you know this?
1
Not at all
2
3
4
5
Perfectly