Exception Handling, File Handling & Database Concepts
Exception Handling
Syntax Error (Passing Error)
A mistake in the program that violates the rules of the programming language.
occurs during the execution of the program
Definition of Syntax Error
Occurs when the programmer has not followed the rules of Python while writing the code.
Exception
errors that are triggered automatically and can be handles through a program code
Purpose of Exception Handling
Allows a program to deal with runtime errors instead of abruptly crashing.
try Block
catches the code that might raise an exception..
Common Built-in Exceptions
SyntaxError,ValueError,IOError,KeyboardInterrupt,ImportError,EOFError,ZeroDivisionError,IndexError,NameError,IndentationError,TypeError,OverflowError.
Consequence of Unhandled Exceptions
Program might stop execution or crash
File Handling
Text File vs. Binary File
Text File
Stores characters encoded in ASCII/Unicode.
Human-readable; lines end with newline (
\n).Typical extension:
.txt.Binary File
Stores raw bytes (
0and1).Not directly human-readable; used for images, videos, or pickled Python objects.