File tree Expand file tree Collapse file tree 2 files changed +27
-6
lines changed
00-playground/40-cursor-ai-intro Expand file tree Collapse file tree 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 11def 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 } " )
49
510def 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 ""
823
924def 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 } " )
1232
1333def parse_input (text : str ) -> str :
1434 return text .strip ('\n ' )
You can’t perform that action at this time.
0 commit comments