[TuT]Error Handling

Posts 1–3 of 3 · Page 1 of 1
[TuT]Error Handling
Example: when making a texture remover, you might get an error saying that File isnt found
Code:
File.Move("C:\Documents and Settings\Owner\Desktop\File.txt", "C:\Documents and Settings\Owner\Desktop\File2.Txt")
Lets say File.txt doesnt exist, then the program will crash, because it cant move a file that isnt there. To fix it
Code:
Try 
File.Move("C:\Documents and Settings\Owner\Desktop\File.txt", "C:\Documents and Settings\Owner\Desktop\File2.Txt")
Catch Ex as Exception
MessageBox.Show("File not found")
End Try
When using that code, if File.txt doesnt exist, then it will not crash, but instead pop up a messagebox.
That would work, but it's too general.
Because if the file is in use or has read only attributes, your little error would pop up with a false error. The correct code would be:

Code:
Try 
File.Move("C:\Documents and Settings\Owner\Desktop\File.txt", "C:\Documents and Settings\Owner\Desktop\File2.Txt")
Catch Ex as Exception
MessageBox.Show(Ex.Message)
End Try
Ex.Message
Ex.Message
Ex.Message
Ex.Message
Ex.Message

wait nvr mind
Posts 1–3 of 3 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Talk with us