Exception handling

  • Thread starter Thread starter STom
  • Start date Start date
S

STom

I had assumed that if I have a try catch statement in Func1 and then receive
an exception, that it would throw one in Func0. Is that not correct? All
that happens is that it Throws an exception in Func1 and then goes to End
Try and keeps on moving.

private function Func0()

try
Func1()
catch ex as Exception
end try

end function

private function Func1()

try
catch ex as Exception
end try

end function


Thanks.
STom
 
STom said:
I had assumed that if I have a try catch statement in Func1 and then
receive an exception, that it would throw one in Func0. Is that not
correct? All that happens is that it Throws an exception in Func1 and
then goes to End Try and keeps on moving.

private function Func0()

try
Func1()
catch ex as Exception
end try

end function

private function Func1()

try
catch ex as Exception
end try

end function


If you catch a ball and do not throw it again, nobody will have to catch it
again.
 
Since you caught the exception in Func1, it won't bubble
up to Func0. Omit the try block and then Func0 will
handle it.

Example:

Private Function Func0() As Boolean

Try
Func1()
Catch ex As Exception
MessageBox.Show("Caught")
End Try

End Function

Private Function Func1() As Boolean
Dim i As Int32 = 0

'-- Throws the error to Func0
i = 50 \ i

End Function
 
* "STom said:
I had assumed that if I have a try catch statement in Func1 and then receive
an exception, that it would throw one in Func0. Is that not correct? All
that happens is that it Throws an exception in Func1 and then goes to End
Try and keeps on moving.

You are catching the exception, that's why it isn't thrown again. Have
a look at the docs for the 'Throw' keyword...
 
Back
Top