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

Exception handling in base(abstract) or derived class.

P: n/a
Hi,

I'm a newbie to OOP and VB.Net. In the business layer, I have a base
class, which is an abstract class in VB.Net. The derived class
overrides a method and calls other methods in the base class. To make
it more clear:

Class NotInheritable BaseAbstract
Sub Method1()
code
end Sub

Sub Method2()
code
Calls Method1
code
end Sub

Sub Method3()
code
Calls Method2
code
End Sub

Overidable Sub Method4()
End Sub

End Class

Class Derived : Inherits BaseAbstract
Overrides Sub Method4()
code
Calls Method3
code
End Sub
End Class

The UI creates an object of Derived class.

I wanted to know what's the best way to handle exceptions? I know I
should have thought about in the design phase :(

Thanks for your help.
hillcountry74

Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
> I wanted to know what's the best way to handle exceptions?

What exception? Generally speaking, you ignore exceptions unless you know
how to handle them. Of course, a global exception error to log those you
didn't expect is a good thing.

--
Jonathan Allen
"hillcountry74" <sh*******@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi,

I'm a newbie to OOP and VB.Net. In the business layer, I have a base
class, which is an abstract class in VB.Net. The derived class
overrides a method and calls other methods in the base class. To make
it more clear:

Class NotInheritable BaseAbstract
Sub Method1()
code
end Sub

Sub Method2()
code
Calls Method1
code
end Sub

Sub Method3()
code
Calls Method2
code
End Sub

Overidable Sub Method4()
End Sub

End Class

Class Derived : Inherits BaseAbstract
Overrides Sub Method4()
code
Calls Method3
code
End Sub
End Class

The UI creates an object of Derived class.

I wanted to know what's the best way to handle exceptions? I know I
should have thought about in the design phase :(

Thanks for your help.
hillcountry74

Nov 21 '05 #2

P: n/a
Thanks for replying.

Sorry, I was not clear in my question. What I meant was, where should I
handle unexpected exceptions- in the base or derived class?

If I handle them in the base class, how do I notify the derived class
method that an error occurred and not continue processing? The method
calls are nested so, how can I bubble up the info that an error
occurred all the way to the derived class method?

Nov 21 '05 #3

P: n/a
"hillcountry74" <sh*******@yahoo.com> wrote in
news:11**********************@g14g2000cwa.googlegr oups.com:

Personally I use functions in stead of methods in these cases. The
function can return True if the code executed nicely, otherwise it
returns False.

Hope this helps.

Nano
Thanks for replying.

Sorry, I was not clear in my question. What I meant was, where should
I
handle unexpected exceptions- in the base or derived class?

If I handle them in the base class, how do I notify the derived class
method that an error occurred and not continue processing? The method
calls are nested so, how can I bubble up the info that an error
occurred all the way to the derived class method?


Nov 21 '05 #4

P: n/a
> Sorry, I was not clear in my question. What I meant was, where should I
handle unexpected exceptions- in the base or derived class?
Since you are calling it an unexpected exception, I am assuming that the
base class doesn't really know what to do with the error. That's fine.
The method
calls are nested so, how can I bubble up the info that an error
occurred all the way to the derived class method?
Simply don't catch the exception. It will keep bubbling up until it reaches
a point where you know what to do or it hits the global exception handler..
Function A
SomethingDangerous() 'this might throw an exception
End Function

Function B
Try
A()
Catch err as FileNotFoundException
Msgbox "Couldn't find the file"
Catch err as FileLockedException 'I made up this exception, don't feel
like looking up the real one
Msgbox "Another program is using that file."
End Try 'any other exception like Out Of memory will continue to
bubble up
End Function
--
Jonathan Allen
"hillcountry74" <sh*******@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com... Thanks for replying.

Sorry, I was not clear in my question. What I meant was, where should I
handle unexpected exceptions- in the base or derived class?

If I handle them in the base class, how do I notify the derived class
method that an error occurred and not continue processing? The method
calls are nested so, how can I bubble up the info that an error
occurred all the way to the derived class method?

Nov 21 '05 #5

P: n/a
That has caused a lot of problems for me. We have a lot of code that does
that. The problem is, we never know why the function failed. Eating the
exception and returning false makes fixing the underlying problem very
difficult.

--
Jonathan Allen
"Nano" <no****@wherei.am> wrote in message
news:cl**********************@phobos.telenet-ops.be...
"hillcountry74" <sh*******@yahoo.com> wrote in
news:11**********************@g14g2000cwa.googlegr oups.com:

Personally I use functions in stead of methods in these cases. The
function can return True if the code executed nicely, otherwise it
returns False.

Hope this helps.

Nano
Thanks for replying.

Sorry, I was not clear in my question. What I meant was, where should
I
handle unexpected exceptions- in the base or derived class?

If I handle them in the base class, how do I notify the derived class
method that an error occurred and not continue processing? The method
calls are nested so, how can I bubble up the info that an error
occurred all the way to the derived class method?

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.