How to cleanup .NET exception?
Dear Gurus:
how can i cleanup an exception occurred in Try section or don't throw the exception to the caller?
i try to start a process and if it fails, i would like to do something else and not throw any exception from here.
Thanks,
[267 byte] By [
chfyin] at [2007-11-20 11:44:33]

# 1 Re: How to cleanup .NET exception?
Post some code, and describe what you are trying to do.
# 2 Re: How to cleanup .NET exception?
Hi David, thank you for replying my post. here is the code.
Try
Dim ex As Exception
proInfo.Password = getOldPass() 'assign old password
proInfo.FileName = filePath & "doit"
proInfo.WorkingDirectory = filePath
proInfo.UseShellExecute = False
proInfo.CreateNoWindow = False
proInfo.UserName = "test"
Process.Start(proInfo)
''' Here is issue: if the process fails, let's say password is wrong,
''' I would like to change the password and restart it.
''' since I could not catch the Process.Start(proInfo)
''' error, I try it this way
Catch exp As Exception
If ex.Message.Substring(0, 13) = "Logon failure" Then
Try
ProInfo.Password = getNewPass() 'assign the new password
Process.Start(ProInfo)
''' this Process.Start(ProInfo) will not run
Catch exp As Exception
End Try
End If
End Try
''' also, if it is possible, i would like to cleanup this exception here so it will
''' not be passed to caller.
chfyin at 2007-11-10 3:09:10 >

# 3 Re: How to cleanup .NET exception?
How about
Dim boo as BOOL = Process.Start(proInfo)
Should return TRUE if it starts a new process.
# 4 Re: How to cleanup .NET exception?
Hi, David:
it does not work. :mad: the following is the error message.
"Error: Value of type 'System.Diagnostics.Process' cannot be converted to 'Boolean'."
chfyin at 2007-11-10 3:11:20 >

# 5 Re: How to cleanup .NET exception?
E.g.Do
Dim password As String = GetPassword()
'...
Try
Process.Start(psi)
Exit Do
Catch
End Try
Loop
# 6 Re: How to cleanup .NET exception?
How about
Dim boo as BOOL = Process.Start(proInfo)
Should return TRUE if it starts a new process.That should be:
Dim boo As Boolean = (Process.Start(proInfo) IsNot Nothing)but that doesn't necessarily tell you what you want to know.
# 7 Re: How to cleanup .NET exception?
Hi, jmcilhinney, thank you for your replying.
1. the do...loop won't work. if Process.Start(psi) fails, it will jump to Catch directly, the Exit DO will never run.
2. the "Dim boo As Boolean = (Process.Start(proInfo) IsNot Nothing)" is right, but if Process.Start(proInfo) fails, it does not give you the chance to test boo and jump to Catch directly.
the problem is once Process.Start(psi) fails, it does not give you a chance to do anything and jumps to Catch directly. this is why i tried to do something in the Catch section. however, there are two issues.
first, like the code i posted earlier, the Process.start(proInfo) in the Catch section won't run.
second, the exception will be thrown to caller, and will cause problem there.
chfyin at 2007-11-10 3:14:22 >

# 8 Re: How to cleanup .NET exception?
Isn't that the whole point? If Process.Start fails then it will jump to the Catch block and go back to the start of the loop, continuing so until the process starts. Isn't that what you were asking for?
# 9 Re: How to cleanup .NET exception?
Isn't that the whole point? If Process.Start fails then it will jump to the Catch block and go back to the start of the loop, continuing so until the process starts. Isn't that what you were asking for?
Hi, jmcilhinney:
it is very good thinking :thumb: , i got it. thank you very much. :D
chfyin at 2007-11-10 3:16:25 >
