views:

77

answers:

5

Hi, i would like to know if there is a Way that when an exception is thrown to let the program continue aftare the exception was thronw for example

 try 

      line 1
      line 2
      line 3
      line 4 ( here the exception is throw and jumps to the catch)
      line 5  <-- i would like the program to continue its execution after loggin the error
      line 6  

   catch ex as exception

       log(ex.tostring)

    end try

Thanks for any comments

A: 

VB.net does not support this type of construct. Once the exception unwinds the stack, it can't be unwound back again. Some languages do permit you to resume the exception, but they require more sophisticated stack management – essentially coroutines.

Thom Smith
A: 
try 
  line 1
catch ex as exception
   log(ex.tostring)
end try
try
  line 2
catch ex as exception
   log(ex.tostring)
end try
try
  line 3
catch ex as exception
   log(ex.tostring)
end try
try
  line 4 ( here the exception is throw and jumps to the catch)
catch ex as exception
   log(ex.tostring)
end try
try
  line 5  <-- i would like the program to continue its execution after loggin the error
catch ex as exception
   log(ex.tostring)
end try
try
  line 6  
catch ex as exception
end try
S.Lott
Did you feel the need to take a shower after typing that? :)
Jay Riggs
aww...you beat me to it :) and if you didn't feel like creating all the try-catch blocks there's always the dreaded goto statement. But I wouldn't suggest that!
townsean
uff well it seems like it is the only way to go .. thanks
carlos
@carlos: as opposed to what? How else can this be done?
S.Lott
+1  A: 

On Error Resume Next is still available in VB.NET, but at the mutual exclusion of structured exception handling Your other option seems to be separate Try..Catch around each statement

But IMHO sweeping exceptions isn't a great strategy - what is causing line 4 to cause an exception?

nonnb
In this case the exception is couse by a dbnullconversion to int after reading from a dB ... but this was just one data of many others, and is why i wanted to keep reading ..Thanks !! for the comments !
carlos
+1  A: 

If you're doing something that you know how to recover from or that isn't vital, you're supposed to wrap just that line in the try/catch with a specific catch. e.g.

try

  line 1
  line 2
  line 3
  Try
     line 4 ( here the exception is throw and jumps to the catch)
  Catch iox as IOException ' or whatever type is being thrown
     'log it
  End Try
  line 5  <-- i would like the program to continue its execution after loggin the error
  line 6  

catch ex as exception

   log(ex.tostring)

end try
Nikki9696
A: 

If I am not mistaken the "Best Practices for Handling Exceptions" says if you can check for an error that will likely occur then check for that condition. If you can check for dbnull then do so.

dbasnett