473,805 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to catch exceptions?

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?

Jul 24 '08 #1
7 2232
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.
SmtpFailedRecip ientException: Represents the exception that is thrown
when the SmtpClient is not able to complete a Send or SendAsync
operation to a particular recipient.
SmtpFailedRecip ientsException: 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
Jul 24 '08 #2
Oh yea I see, exceptions are classes and listed in the section for classes
which will be typical for any namespace. Duh.

"Munna" <mu******@gmail .comwrote in message
news:52******** *************** ***********@s50 g2000hsb.google groups.com...
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.
SmtpFailedRecip ientException: Represents the exception that is thrown
when the SmtpClient is not able to complete a Send or SendAsync
operation to a particular recipient.
SmtpFailedRecip ientsException: 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
Jul 24 '08 #3
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" <mu******@gmail .comwrote in message
news:52******** *************** ***********@s50 g2000hsb.google groups.com...
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.
SmtpFailedRecip ientException: Represents the exception that is thrown
when the SmtpClient is not able to complete a Send or SendAsync
operation to a particular recipient.
SmtpFailedRecip ientsException: 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

Aug 5 '08 #4
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
Aug 5 '08 #5
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
Aug 5 '08 #6
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
Aug 5 '08 #7

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(st ring To, string From, string
Subject, string Body)
{
if (gWaitingForSen dToComplete)
{
AppendDebug("Wa iting 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(T o);
Mailer.Subject = Subject;
Mailer.Body = Body;
Mailer.IsBodyHt ml = false;
Mailer.Priority = System.Net.Mail .MailPriority.H igh;
SmtpClient SC = new SmtpClient("hid den");
SC.Credentials = new NetworkCredenti al("hidden", "hidden");
SC.SendComplete d += new
SendCompletedEv entHandler(Smtp Client_OnComple ted);
object UserState = Mailer;

try
{
AppendDebug("Tr ying to send: " + Subject);
SC.SendAsync(Ma iler, UserState);
gWaitingForSend ToComplete = true;
}
catch (Exception ex)
{
gWaitingForSend ToComplete = false;
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerExcept ion;
}

AppendDebug(err orMessage);

}

}

public static void SmtpClient_OnCo mpleted(object sender,
AsyncCompletedE ventArgs e)
{
gWaitingForSend ToComplete = false;
System.Net.Mail .MailMessage mail =
(System.Net.Mai l.MailMessage)e .UserState;
AppendDebug("Ca llback: " + mail.Subject);

if (e.Error == null)
{
AppendDebug("No errors");
MessageBox.Show ("SNM SENT No CallBack Errors" + mail.Subject
);
}
else
{
AppendDebug("Er rors " + mail.Subject + " " +
e.Error.ToStrin g());
MessageBox.Show ("SNM CallBack ERRORS" + mail.Subject + " " +
e.Error.ToStrin g());
if (mail.Subject.S tartsWith("#"))
{
int Num = int.Parse(mail. Subject.Substri ng(1, 1));
if (Num >= 9)
{
AppendDebug("Ga ve up trying to send");
return;
}
Num++;
mail.Subject = "#" + Num + mail.Subject.Su bstring(2,
mail.Subject.Le ngth - 2);
}
else
{
mail.Subject = "#1" + mail.Subject;

}
Thread.Sleep(50 00);
SendNetEmail(ma il.To.ToString( ), mail.From.ToStr ing(),
mail.Subject, mail.Body);
}
}

public static void AppendDebug(str ing Txt)
{

long ts = DateTime.Now.Ti cks / TimeSpan.TicksP erMillisecond;
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 .SendMailAsyncR esult.End(IAsyn cResult result)
at System.Net.Mail .SmtpTransport. EndSendMail(IAs yncResult result)
at System.Net.Mail .SmtpClient.Sen dMailCallback(I AsyncResult 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
Aug 6 '08 #8

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

Similar topics

10
30329
by: Gary.Hu | last post by:
I was trying to catch the Arithmetic exception, unsuccessfully. try{ int a = 0, b = 9; b = b / a; }catch(...){ cout << "arithmetic exception was catched!" << endl; } After ran the program, it quitted with core dumped. %test
24
2365
by: Steven T. Hatton | last post by:
If I understand correctly, I have no assurance that I can determine the type of a simple class instance thrown as an exception unless I explicitly catch it by name. (non-derived classes having no virtual funcitons have no rtti) That is, there is no way to do something like: try{ funct_from_3rd_party(); } catch(...){ std:err << extract_name() << std::endl; }
8
2738
by: Z D | last post by:
Hi, I was wondering what's the point of "finally" is in a try..catch..finally block? Isn't it the same to put the code that would be in the "finally" section right after the try/catch block? (ie, forget the finally block and just end the try/catch and put the code after the try/catch block). Or does the "finally" construct add some additional functionality?
9
343
by: Steven Blair | last post by:
Hi, I need to catch exceotions on File.Delete() After checking the help, I have noticed that thgere are serevral Exceptions that can be thrown. My question is, should I catch all thes Exceptions, or if I simply do the following: try
13
3727
by: Benny | last post by:
Hi, I have something like this: try { // some code } catch // note - i am catching everything now {
23
3084
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally block. But, I prefer to dim them "on the fly" only if needed (save as much resources as possible). A little further... I may wish to create a sqlcommand and datareader object ONLY if certain conditions are met. But, if I want to clean these up in the...
9
1654
by: Bob Achgill | last post by:
I really like this function but have tried to slow down on using it because I get a 1 second pause each time I use it. I don't really understand why the computer has to think for 1 second! Especially at 2.8 GZ and 1GB RAM. The same pause happens on different situations: database access Trys, Array access Trys. Hummm??
32
6132
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I understand Finally runs whether an error was caught or not, I haven't found a use for finally yet.
23
2334
by: pigeonrandle | last post by:
Hi, Does this bit of code represent complete overkill?! try { //create a treenode TreeNode tn = new TreeNode(); //add it to a treeview tv.Nodes.Add(tn);
6
1932
by: john_c | last post by:
FxCopy says this about catching general exceptions: "You should not catch Exception or SystemException. Catching generic exception types can hide run-time problems from the library user, and can complicate debugging. You should catch only those exceptions that you can handle gracefully." This is for a winform app but applies to asp.net also. There are some code blocks you may know which exception may get thrown and others
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10361
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10103
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.