473,383 Members | 1,788 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

catching a specific exception

cj
When I run myMAPIMessage.Send(True) if the user cancels the resulting
email it causes an exception. How do I trap this particular exception
and say that's ok?

try
myMAPIMessage.Send(True)
catch ex as ??????
'this is ok
catch ex as exception
'show these
messagebox.show(ex.message)
end try

Here is what the exception I'm getting is as shown in the command window:

? ex
{System.Runtime.InteropServices.COMException}
[System.Runtime.InteropServices.COMException]:
{System.Runtime.InteropServices.COMException}
HelpLink: "MAPI98.CHM#32001"
InnerException: Nothing
Message: "User cancelled process"
Source: "MAPIMessages"
StackTrace: " at MSMAPI.MAPIMessagesClass.Send(Object vDialog)
at WindowsApplication20.Form1.SndMAPIMail(String subj, String msg)
in C:\Documents and Settings\cj\My Documents\Visual Studio
Projects\WindowsApplication20\Form1.vb:line 565"
TargetSite: {System.Reflection.RuntimeMethodInfo}
May 19 '06 #1
5 2044

cj,

Are all the exceptions COMExceptions?

If so, you might need to look at the exception's message to determine
whether to display an exception message. Something like:

Catch ex As Exception
If NOT ex.Message = "User cancelled process" Then
Msgbox ex.Message ...
End IF

In general I don't recommend looking at the exception's Message text to make
a decision, since the text might change in a future release, but you might
need to in this case.

Kerry Moorman

"cj" wrote:
When I run myMAPIMessage.Send(True) if the user cancels the resulting
email it causes an exception. How do I trap this particular exception
and say that's ok?

try
myMAPIMessage.Send(True)
catch ex as ??????
'this is ok
catch ex as exception
'show these
messagebox.show(ex.message)
end try

Here is what the exception I'm getting is as shown in the command window:

? ex
{System.Runtime.InteropServices.COMException}
[System.Runtime.InteropServices.COMException]:
{System.Runtime.InteropServices.COMException}
HelpLink: "MAPI98.CHM#32001"
InnerException: Nothing
Message: "User cancelled process"
Source: "MAPIMessages"
StackTrace: " at MSMAPI.MAPIMessagesClass.Send(Object vDialog)
at WindowsApplication20.Form1.SndMAPIMail(String subj, String msg)
in C:\Documents and Settings\cj\My Documents\Visual Studio
Projects\WindowsApplication20\Form1.vb:line 565"
TargetSite: {System.Reflection.RuntimeMethodInfo}

May 19 '06 #2
cj
I guess they would be. Now that I think of it in that light I guess if
I was using something specific to .net rather than mapi I might be able
to do it like I was thinking. Anyway, yea I can do it by looking at the
message. It'll be ok in this situation.

Kerry Moorman wrote:
cj,

Are all the exceptions COMExceptions?

If so, you might need to look at the exception's message to determine
whether to display an exception message. Something like:

Catch ex As Exception
If NOT ex.Message = "User cancelled process" Then
Msgbox ex.Message ...
End IF

In general I don't recommend looking at the exception's Message text to make
a decision, since the text might change in a future release, but you might
need to in this case.

Kerry Moorman

"cj" wrote:
When I run myMAPIMessage.Send(True) if the user cancels the resulting
email it causes an exception. How do I trap this particular exception
and say that's ok?

try
myMAPIMessage.Send(True)
catch ex as ??????
'this is ok
catch ex as exception
'show these
messagebox.show(ex.message)
end try

Here is what the exception I'm getting is as shown in the command window:

? ex
{System.Runtime.InteropServices.COMException}
[System.Runtime.InteropServices.COMException]:
{System.Runtime.InteropServices.COMException}
HelpLink: "MAPI98.CHM#32001"
InnerException: Nothing
Message: "User cancelled process"
Source: "MAPIMessages"
StackTrace: " at MSMAPI.MAPIMessagesClass.Send(Object vDialog)
at WindowsApplication20.Form1.SndMAPIMail(String subj, String msg)
in C:\Documents and Settings\cj\My Documents\Visual Studio
Projects\WindowsApplication20\Form1.vb:line 565"
TargetSite: {System.Reflection.RuntimeMethodInfo}

May 19 '06 #3

Kerry Moorman wrote:
cj,

Are all the exceptions COMExceptions?

If so, you might need to look at the exception's message to determine
whether to display an exception message. Something like:

Catch ex As Exception
If NOT ex.Message = "User cancelled process" Then
Msgbox ex.Message ...
End IF

In general I don't recommend looking at the exception's Message text to make
a decision, since the text might change in a future release, but you might
need to in this case.

Kerry Moorman

With a COMException, you can always look at the ErrorCode property. It
will return the HRESULT of the error. You have to look up the specific
HRESULTS, but it is a little better then using the Message property,
IMHO.

--
Tom Shelton [MVP]

May 19 '06 #4
cj
I'll look into it. Thanks!

Tom Shelton wrote:
Kerry Moorman wrote:
cj,

Are all the exceptions COMExceptions?

If so, you might need to look at the exception's message to determine
whether to display an exception message. Something like:

Catch ex As Exception
If NOT ex.Message = "User cancelled process" Then
Msgbox ex.Message ...
End IF

In general I don't recommend looking at the exception's Message text to make
a decision, since the text might change in a future release, but you might
need to in this case.

Kerry Moorman

With a COMException, you can always look at the ErrorCode property. It
will return the HRESULT of the error. You have to look up the specific
HRESULTS, but it is a little better then using the Message property,
IMHO.

--
Tom Shelton [MVP]

May 19 '06 #5
cj,
In addition to Tom's suggestion, you can use the When clause of the catch to
catch an exception based on specific attributes.

For example:

To only catch COM E_NOT_FOUND exceptions (in CDO) I use:

Try
Return GetField(name)
Catch ex As COMException When ex.ErrorCode =
MAPI.CdoErrorType.CdoE_NOT_FOUND
Return AddField(name, type)
End Try
Or to catch WebExceptions from HttpWebResponses, I would use:

Try
m_response = DirectCast(m_request.GetResponse(),
HttpWebResponse)
Catch ex As WebException When TypeOf ex.Response Is HttpWebResponse
m_response = DirectCast(ex.Response, HttpWebResponse)
End Try

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"cj" <cj@nospam.nospam> wrote in message
news:ui**************@TK2MSFTNGP04.phx.gbl...
| When I run myMAPIMessage.Send(True) if the user cancels the resulting
| email it causes an exception. How do I trap this particular exception
| and say that's ok?
|
| try
| myMAPIMessage.Send(True)
| catch ex as ??????
| 'this is ok
| catch ex as exception
| 'show these
| messagebox.show(ex.message)
| end try
|
| Here is what the exception I'm getting is as shown in the command window:
|
| ? ex
| {System.Runtime.InteropServices.COMException}
| [System.Runtime.InteropServices.COMException]:
| {System.Runtime.InteropServices.COMException}
| HelpLink: "MAPI98.CHM#32001"
| InnerException: Nothing
| Message: "User cancelled process"
| Source: "MAPIMessages"
| StackTrace: " at MSMAPI.MAPIMessagesClass.Send(Object vDialog)
| at WindowsApplication20.Form1.SndMAPIMail(String subj, String msg)
| in C:\Documents and Settings\cj\My Documents\Visual Studio
| Projects\WindowsApplication20\Form1.vb:line 565"
| TargetSite: {System.Reflection.RuntimeMethodInfo}
May 19 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Karl A. Krueger | last post by:
I'm in the middle of refactoring a small mod_python Web application, which uses the Publisher handler. This application is currently a single main Python file (which loads several other files as...
2
by: Keith Bolton | last post by:
I am handling exceptions currently using try, except. Generally I don't handle specific exceptions and am catching all. Then if an exception occurs, I would like to capture that error string....
7
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block...
12
by: Vasco Lohrenscheit | last post by:
Hi, I have a Problem with unmanaged exception. In the debug build it works fine to catch unmanaged c++ exceptions from other dlls with //managed code: try { //the form loads unmanaged dlls...
2
by: Eric Sabine | last post by:
I built a generic exception handler form which allows the user to get information from it, print it, email it, etc. for exceptions for which I explicitly didn't handle in code, such as missing...
3
by: Peter A. Schott | last post by:
I know there's got to be an easy way to do this - I want a way to catch the error text that would normally be shown in an interactive session and put that value into a string I can use later. I've...
12
by: Karlo Lozovina | last post by:
I'm not sure if Python can do this, and I can't find it on the web. So, here it goes: try: some_function() except SomeException: some_function2() some_function3() ...
5
by: Tom P. | last post by:
I have a situation that requires me to catch two different types of exceptions but do the same processing. Is there a way to do this? In VB you can stack the Catch statements but what do I do in...
3
by: john | last post by:
I wrapped some fortran code using F2PY and need to be able to catch fortran runtime errors to run the following: # "grid" is a wrapped fortran module # no runtime errors incurred when run with...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.