|
-
Jul 14th, 2016, 09:59 AM
#2
Re: SystemIOException
I'd have to see a good bit more of your code to give you specialized advice, but in general when you know a particular exception is coming, you use a Try..Catch to handle it.
IOException is sort of general and could mean a lot of things, so you might have to dig into it to see if it's the right one. Here's an option:
Code:
Try
' The code that saves the file
Catch ex As System.IO.IOException
If ex.Message = "Whatever the message is, arrogantly assuming everyone speaks English" Then
' This is the case where they pulled the drive out, yell at them with a message box
Else
' This is some other error case, best to let it burn
Throw
End If
End Catch
That code will intercept this specific IOException (assuming you put the right String in for the message) and handle that without crashing. Any other IOException will continue to crash the program. This sounds bad, but is ultimately good. If you willy-nilly write code that ignores exceptions, you can get in situations where obvious assumptions are no longer true, and your program behaves in weird ways that cost you days of debugging time.
If you can, try to find a better way to figure out if it's the right IOException than using the Message property. That one can change with the system language. I'm not sure if a better way does exist, there isn't always some unique property to check. That's why it's a very bad idea to throw very general exceptions like IOException, Microsoft.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|