Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to catch exceptions?

Reply
Thread Tools

How to catch exceptions?

 
 
JackPot
Guest
Posts: n/a
 
      07-24-2008
Actually, I'm interested in learning where the different types of exceptions
are documented for a specific type of class, let us say for instance classes
in the System.Net.Mail Namespace. Shouldn't the types be documented on the
same page as the class, its members and properties?

 
Reply With Quote
 
 
 
 
Munna
Guest
Posts: n/a
 
      07-24-2008
Hi


http://msdn.microsoft.com/en-us/libr....net.mail.aspx

SmtpException: Represents the exception that is thrown when the
SmtpClient is not able to complete a Send or SendAsync operation.
SmtpFailedRecipientException: Represents the exception that is thrown
when the SmtpClient is not able to complete a Send or SendAsync
operation to a particular recipient.
SmtpFailedRecipientsException: Infrastructure. The exception that is
thrown when e-mail is sent using an SmtpClient and cannot be delivered
to all recipients.

yes they are mentioned there...

Best of luck

-------
Munna

www.munna.shatkotha.com/blog
www.munna.shatkotha.com
www.shatkotha.com
 
Reply With Quote
 
 
 
 
JackPot
Guest
Posts: n/a
 
      07-24-2008
Oh yea I see, exceptions are classes and listed in the section for classes
which will be typical for any namespace. Duh.

"Munna" <> wrote in message
news:52018dab-e7c6-40e1-9bfe-...
> Hi
>
>
> http://msdn.microsoft.com/en-us/libr....net.mail.aspx
>
> SmtpException: Represents the exception that is thrown when the
> SmtpClient is not able to complete a Send or SendAsync operation.
> SmtpFailedRecipientException: Represents the exception that is thrown
> when the SmtpClient is not able to complete a Send or SendAsync
> operation to a particular recipient.
> SmtpFailedRecipientsException: Infrastructure. The exception that is
> thrown when e-mail is sent using an SmtpClient and cannot be delivered
> to all recipients.
>
> yes they are mentioned there...
>
> Best of luck
>
> -------
> Munna
>
> www.munna.shatkotha.com/blog
> www.munna.shatkotha.com
> www.shatkotha.com


 
Reply With Quote
 
Moon
Guest
Posts: n/a
 
      08-05-2008
CallBack for Asynch does not work consistently. i.e. quite often it does not
get triggered. Can Anyone help?

"JackPot" wrote:

> Oh yea I see, exceptions are classes and listed in the section for classes
> which will be typical for any namespace. Duh.
>
> "Munna" <> wrote in message
> news:52018dab-e7c6-40e1-9bfe-...
> > Hi
> >
> >
> > http://msdn.microsoft.com/en-us/libr....net.mail.aspx
> >
> > SmtpException: Represents the exception that is thrown when the
> > SmtpClient is not able to complete a Send or SendAsync operation.
> > SmtpFailedRecipientException: Represents the exception that is thrown
> > when the SmtpClient is not able to complete a Send or SendAsync
> > operation to a particular recipient.
> > SmtpFailedRecipientsException: Infrastructure. The exception that is
> > thrown when e-mail is sent using an SmtpClient and cannot be delivered
> > to all recipients.
> >
> > yes they are mentioned there...
> >
> > Best of luck
> >
> > -------
> > Munna
> >
> > www.munna.shatkotha.com/blog
> > www.munna.shatkotha.com
> > www.shatkotha.com

>
>

 
Reply With Quote
 
Göran Andersson
Guest
Posts: n/a
 
      08-05-2008
Moon wrote:
> CallBack for Asynch does not work consistently. i.e. quite often it does not
> get triggered. Can Anyone help?


Don't ask a totally unrelated question in an existing thread. Start a
new thread, and explain what it is that you are doing. There are several
classes with asynchronous methods, specify which one is it that you are
using.

--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
Moon
Guest
Posts: n/a
 
      08-05-2008
Dear Goran,

I believe this thread is about SMTPClient exceptions. That is what my
question is about. I am trying to catch the exception from an async
SMTPCleint send via the callback sendcompleted functionality.

I felt that this was appropriate for this thread.

I apologise if you still think this is not the case.

Moon


"Göran Andersson" wrote:

> Moon wrote:
> > CallBack for Asynch does not work consistently. i.e. quite often it does not
> > get triggered. Can Anyone help?

>
> Don't ask a totally unrelated question in an existing thread. Start a
> new thread, and explain what it is that you are doing. There are several
> classes with asynchronous methods, specify which one is it that you are
> using.
>
> --
> Göran Andersson
> _____
> http://www.guffa.com
>

 
Reply With Quote
 
Göran Andersson
Guest
Posts: n/a
 
      08-05-2008
Moon wrote:
> Dear Goran,
>
> I believe this thread is about SMTPClient exceptions. That is what my
> question is about. I am trying to catch the exception from an async
> SMTPCleint send via the callback sendcompleted functionality.
>
> I felt that this was appropriate for this thread.
>
> I apologise if you still think this is not the case.
>
> Moon


I see. It seemed totally irrelevant as your question is about
asynchronous calls. An asynchronous process doesn't throw exceptions to
communicate back to the caller.

The documentation says that you need to wait for the previos send to
complete before sending again, does your code follow that restriction?

What you are talking about doesn't seem to be a common problem, so it's
probably related to your specific code. If you posted some of it, I (or
anyone else here) can take a look at it.

>
> "Göran Andersson" wrote:
>
>> Moon wrote:
>>> CallBack for Asynch does not work consistently. i.e. quite often it does not
>>> get triggered. Can Anyone help?

>> Don't ask a totally unrelated question in an existing thread. Start a
>> new thread, and explain what it is that you are doing. There are several
>> classes with asynchronous methods, specify which one is it that you are
>> using.
>>
>> --
>> Göran Andersson
>> _____
>> http://www.guffa.com
>>



--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
Moon
Guest
Posts: n/a
 
      08-06-2008

Hi Goran,

Actually I had not spotted the need to wait before sending next - seems a
bit odd for async. Howvever, I ammended my code and it works much better. But
I do get erros which are now caught by CallBack, BUT for no obvious reason.
If I immediately resend the same message it then works...

If have included code below: if you look at my log at the end, you can see I
try to send and email "TEST EMAIL NC 11:29:10" then I am blocked from sending
by my own code whilst I wait fr complete callback - which too a few minutes.
I get system error 4. Then I resend message and it works OK - see OnCompleted
code to ensure I am sending exact same message with only difference being
adding "#1" to front of subject.

Odd eh?

Lawrence


private static void SendNetEmail(string To, string From, string
Subject, string Body)
{
if (gWaitingForSendToComplete)
{
AppendDebug("Waiting for complete New Subject: " + Subject);
return;
}
System.Net.Mail.MailMessage Mailer = new
System.Net.Mail.MailMessage();
Mailer.From = new System.Net.Mail.MailAddress( From);
Mailer.To.Add(To);
Mailer.Subject = Subject;
Mailer.Body = Body;
Mailer.IsBodyHtml = false;
Mailer.Priority = System.Net.Mail.MailPriority.High;


SmtpClient SC = new SmtpClient("hidden");
SC.Credentials = new NetworkCredential("hidden", "hidden");
SC.SendCompleted += new
SendCompletedEventHandler(SmtpClient_OnCompleted);
object UserState = Mailer;

try
{
AppendDebug("Trying to send: " + Subject);
SC.SendAsync(Mailer, UserState);
gWaitingForSendToComplete = true;
}
catch (Exception ex)
{
gWaitingForSendToComplete = false;
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}

AppendDebug(errorMessage);

}

}

public static void SmtpClient_OnCompleted(object sender,
AsyncCompletedEventArgs e)
{
gWaitingForSendToComplete = false;
System.Net.Mail.MailMessage mail =
(System.Net.Mail.MailMessage)e.UserState;
AppendDebug("Callback: " + mail.Subject);

if (e.Error == null)
{
AppendDebug("No errors");
MessageBox.Show("SNM SENT No CallBack Errors" + mail.Subject
);
}
else
{
AppendDebug("Errors " + mail.Subject + " " +
e.Error.ToString());
MessageBox.Show("SNM CallBack ERRORS" + mail.Subject + " " +
e.Error.ToString());
if (mail.Subject.StartsWith("#"))
{
int Num = int.Parse(mail.Subject.Substring(1, 1));
if (Num >= 9)
{
AppendDebug("Gave up trying to send");
return;
}
Num++;
mail.Subject = "#" + Num + mail.Subject.Substring(2,
mail.Subject.Length - 2);
}
else
{
mail.Subject = "#1" + mail.Subject;

}
Thread.Sleep(5000);
SendNetEmail(mail.To.ToString(), mail.From.ToString(),
mail.Subject, mail.Body);
}
}

public static void AppendDebug(string Txt)
{

long ts = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
TextWriter TW = new StreamWriter("C:\\DebugLog.txt", true);
TW.WriteLine(ts.ToString() + " " + Txt);
TW.Close();


}



My LOG from AppendDebug

63353618950380 Trying to send: TEST EMAIL NC 11:29:10
63353618957615 Sending mail
63353618957615 Waiting for complete New Subject: TEST EMAIL NC 11:29:17
63353618960771 Sending mail
63353618960771 Waiting for complete New Subject: TEST EMAIL NC 11:29:20
63353619032193 Callback: TEST EMAIL NC 11:29:10
63353619032193 Errors TEST EMAIL NC 11:29:10 System.Net.Mail.SmtpException:
Syntax error, command unrecognized. The server response was: System error 4
at System.Net.Mail.SendMailAsyncResult.End(IAsyncResu lt result)
at System.Net.Mail.SmtpTransport.EndSendMail(IAsyncRe sult result)
at System.Net.Mail.SmtpClient.SendMailCallback(IAsync Result result)
63353619222350 Trying to send: #1TEST EMAIL NC 11:29:10
63353619223303 Callback: #1TEST EMAIL NC 11:29:10
63353619223303 No errors






"Göran Andersson" wrote:

> Moon wrote:
> > Dear Goran,
> >
> > I believe this thread is about SMTPClient exceptions. That is what my
> > question is about. I am trying to catch the exception from an async
> > SMTPCleint send via the callback sendcompleted functionality.
> >
> > I felt that this was appropriate for this thread.
> >
> > I apologise if you still think this is not the case.
> >
> > Moon

>
> I see. It seemed totally irrelevant as your question is about
> asynchronous calls. An asynchronous process doesn't throw exceptions to
> communicate back to the caller.
>
> The documentation says that you need to wait for the previos send to
> complete before sending again, does your code follow that restriction?
>
> What you are talking about doesn't seem to be a common problem, so it's
> probably related to your specific code. If you posted some of it, I (or
> anyone else here) can take a look at it.
>
> >
> > "Göran Andersson" wrote:
> >
> >> Moon wrote:
> >>> CallBack for Asynch does not work consistently. i.e. quite often it does not
> >>> get triggered. Can Anyone help?
> >> Don't ask a totally unrelated question in an existing thread. Start a
> >> new thread, and explain what it is that you are doing. There are several
> >> classes with asynchronous methods, specify which one is it that you are
> >> using.
> >>
> >> --
> >> Göran Andersson
> >> _____
> >> http://www.guffa.com
> >>

>
>
> --
> Göran Andersson
> _____
> http://www.guffa.com
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
catch doesn't catch a thrown exception Marteno Rodia Java 5 08-05-2009 03:30 AM
catch(...) doesn't catch everything Adam C++ 9 02-02-2006 05:02 PM
why catch (...) can not catch such exception John Black C++ 8 08-20-2004 02:34 PM
Trace: Can anyone suggest a good tool to catch trace messages? Rukmal Fernando ASP .Net 4 10-27-2003 09:03 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57