Try Catch Block for a Whole Class

G

Guest

Hi,

I have a Problem when i try to put a Try Catch Block Outside all the
Functions in a Class. But in .Net, it throws an error.

I like to catch all the Unhandled Exception that occured inside a Class so I
need to Put a TRY CATCH Block from the Next Line from where the Class starts.

I need to Achieve the Above Scenerio. Let me know if anyone knows the
Solution for it.

Thanks in Advance
 
T

Tibby

Hi,

I have a Problem when i try to put a Try Catch Block Outside all the
Functions in a Class. But in .Net, it throws an error.

I like to catch all the Unhandled Exception that occured inside a Class so I
need to Put a TRY CATCH Block from the Next Line from where the Class starts.

I need to Achieve the Above Scenerio. Let me know if anyone knows the
Solution for it.

Thanks in Advance

As far as I know, Try...Catch is for method level. So, you would have
to put one in every method (Function/Sub) to catch any and all
unhandled exceptions. The problem I see with that is it's not very
structured. There's some code you absolutly know will not throw an
exception, and then there's some that do. For instance;

Try
Dim a, b as Integer

a=0
b += a + 5
Catch ex As Exception

End Try

If that throws an exception, then there's issues, so from a
performance/size standpoint, the try..catch should be eliminated.
Of course, this is all IMHO, so you can take it with a grain of salt.
But, as far as I know, try..catch is method level only.

Tibby
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top