By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,695 Members | 1,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,695 IT Pros & Developers. It's quick & easy.

Try Catch Block for a Whole Class

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Mon, 16 May 2005 09:08:27 -0700, Solution Seeker
<So************@discussions.microsoft.com> wrote:
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
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.