470,590 Members | 2,525 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,590 developers. It's quick & easy.

Is that possible to convert an Exception object to SMTPException object?

Hi All,

Is that possible to convert an Exception object to SMTPException object. I
tried CType() and it did not work!

Thanks,

Joe
Jan 2 '08 #1
5 1204
"JoeP" <No****@Hotmail.comwrote in message
news:u7**************@TK2MSFTNGP02.phx.gbl...
Hi All,

Is that possible to convert an Exception object to SMTPException object. I
tried CType() and it did not work!

Just throw a new SMTPException...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jan 2 '08 #2
You cannot "upcast" a particular base class object to an instance of a more
specific object that derives from it. The base class ("Exception") has no
idea what the derived object may possibly be. Make sense?

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"JoeP" wrote:
Hi All,

Is that possible to convert an Exception object to SMTPException object. I
tried CType() and it did not work!

Thanks,

Joe
Jan 2 '08 #3
Hi there,

Here is what I need to do. I have an Err handler routine that logs any error either from an
Exception or an SMTPException.

Within the Catch I call the Handler either for the SMTPException or the Exception. There 2 more properties

in the SMTPException that I need to log while they do no exists in the Exception.

In the err handler methods it starts like this:

Public Sub ErrorHandler(ByVal oErrObject As Object, ByVal cErrorType As String)
End Sub

So this way Either oibject could be picked up and I know which one is which based on the cErrorType,
But I am getting a little message saying as follows: System.InvalidCastException when I hover on top
of the oErrObject. It works fine otherwise.

The way I call the above is:

oInquiery.ErrorHandler(smtpEx, "SMTPErr")
Or
oInquiery.ErrorHandler(generalEx, "GeneralErr")

So any ideas?

Thanks,

Joe





"Peter Bromberg [C# MVP]" <pb*******@yahoo.NoSpamMaam.comwrote in message news:BA**********************************@microsof t.com...
You cannot "upcast" a particular base class object to an instance of a more
specific object that derives from it. The base class ("Exception") has no
idea what the derived object may possibly be. Make sense?

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"JoeP" wrote:
>Hi All,

Is that possible to convert an Exception object to SMTPException object. I
tried CType() and it did not work!

Thanks,

Joe
Jan 2 '08 #4
OK the fix for that was:

Public Sub ErrorHandler(ByVal oErrObject As System.Object, ByVal cErrorType As String)
End Sub

Hi there,
Here is what I need to do. I have an Err handler routine that logs any error either from an
Exception or an SMTPException.

Within the Catch I call the Handler either for the SMTPException or the Exception. There 2 more properties

in the SMTPException that I need to log while they do no exists in the Exception.

In the err handler methods it starts like this:

Public Sub ErrorHandler(ByVal oErrObject As Object, ByVal cErrorType As String)
End Sub

So this way Either oibject could be picked up and I know which one is which based on the cErrorType,
But I am getting a little message saying as follows: System.InvalidCastException when I hover on top
of the oErrObject. It works fine otherwise.

The way I call the above is:

oInquiery.ErrorHandler(smtpEx, "SMTPErr")
Or
oInquiery.ErrorHandler(generalEx, "GeneralErr")

So any ideas?

Thanks,

Joe





"Peter Bromberg [C# MVP]" <pb*******@yahoo.NoSpamMaam.comwrote in message news:BA**********************************@microsof t.com...
You cannot "upcast" a particular base class object to an instance of a more
specific object that derives from it. The base class ("Exception") has no
idea what the derived object may possibly be. Make sense?

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"JoeP" wrote:
>Hi All,

Is that possible to convert an Exception object to SMTPException object. I
tried CType() and it did not work!

Thanks,

Joe
Jan 2 '08 #5
You might want to review this article about good practices:

http://blogs.msdn.com/kcwalina/archi...16/396787.aspx

"JoeP" <No****@Hotmail.comwrote in message news:O3**************@TK2MSFTNGP02.phx.gbl...
Hi there,

Here is what I need to do. I have an Err handler routine that logs any error either from an
Exception or an SMTPException.

Within the Catch I call the Handler either for the SMTPException or the Exception. There 2 more properties

in the SMTPException that I need to log while they do no exists in the Exception.

In the err handler methods it starts like this:

Public Sub ErrorHandler(ByVal oErrObject As Object, ByVal cErrorType As String)
End Sub

So this way Either oibject could be picked up and I know which one is which based on the cErrorType,
But I am getting a little message saying as follows: System.InvalidCastException when I hover on top
of the oErrObject. It works fine otherwise.

The way I call the above is:

oInquiery.ErrorHandler(smtpEx, "SMTPErr")
Or
oInquiery.ErrorHandler(generalEx, "GeneralErr")

So any ideas?

Thanks,

Joe





"Peter Bromberg [C# MVP]" <pb*******@yahoo.NoSpamMaam.comwrote in message news:BA**********************************@microsof t.com...
You cannot "upcast" a particular base class object to an instance of a more
specific object that derives from it. The base class ("Exception") has no
idea what the derived object may possibly be. Make sense?

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"JoeP" wrote:
>Hi All,

Is that possible to convert an Exception object to SMTPException object. I
tried CType() and it did not work!

Thanks,

Joe
Jan 2 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Ronald Fischer | last post: by
13 posts views Thread by Alison Givens | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.