File tree 2 files changed +27
-6
lines changed
00-playground/40-cursor-ai-intro
2 files changed +27
-6
lines changed Original file line number Diff line number Diff line change
1
+ Max
Original file line number Diff line number Diff line change 1
1
def write_file (filename : str , text : str ):
2
- with open (filename , "w" ) as f :
3
- f .write (text )
2
+ try :
3
+ with open (filename , "w" ) as f :
4
+ f .write (text )
5
+ except IOError as e :
6
+ print (f"Error writing to file { filename } : { e } " )
7
+ except Exception as e :
8
+ print (f"Unexpected error occurred: { e } " )
4
9
5
10
def read_file (filename : str ) -> str :
6
- with open (filename , "r" ) as f :
7
- return f .read ()
11
+ try :
12
+ with open (filename , "r" ) as f :
13
+ return f .read ()
14
+ except FileNotFoundError :
15
+ print (f"File { filename } not found" )
16
+ return ""
17
+ except IOError as e :
18
+ print (f"Error reading file { filename } : { e } " )
19
+ return ""
20
+ except Exception as e :
21
+ print (f"Unexpected error occurred: { e } " )
22
+ return ""
8
23
9
24
def append_file (filename : str , text : str ):
10
- with open (filename , "a" ) as f :
11
- f .write (text )
25
+ try :
26
+ with open (filename , "a" ) as f :
27
+ f .write (text )
28
+ except IOError as e :
29
+ print (f"Error appending to file { filename } : { e } " )
30
+ except Exception as e :
31
+ print (f"Unexpected error occurred: { e } " )
12
32
13
33
def parse_input (text : str ) -> str :
14
34
return text .strip ('\n ' )
You can’t perform that action at this time.
0 commit comments