?
Solved

pinging without exceptions

Posted on 2003-03-11
6
Medium Priority
?
136 Views
Last Modified: 2010-04-04
I use IdIcmpClient1.Ping, wich works great. But I don't want the program to give an error when the host is unavial.
0
Comment
Question by:Stream12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Accepted Solution

by:
DaFox earned 150 total points
ID: 8112756
Hi.

What about try..except?

try
  ...
  IdIcmpClient1.Ping;
except
end;

Markus
0
 
LVL 6

Expert Comment

by:swift99
ID: 8116500
if you do this then you should handle the exception to determine whether or not it is one that you really want to ignore.  As written, this can hide some nasty bugs.
0
 
LVL 3

Expert Comment

by:smurff
ID: 8117878
remember that if you put it in the Try..Except you will get a message within the delphi IDE but you will not see it when it is compiled.

So to sum up : Even if you put it in a Try..Except, the IDE will show an exception error but when its compiled, it will not be there and it will just run your code below the "Except" section


Regards
Smurff
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:steve_hsk
ID: 8118074
Hi Stream ...

If you're happy using a third party component, that is designed to throw it's own exception type, then this is perfectly valid, and as the guys suggested a simple try .. except statement around the function that causes the exception would work just fine.

Alternatively, you could write your own component using the ICMP.DLL, or use RAW SOCKETS which we can provide examples for.

TRY ... EXCEPT EXAMPLE :

// Try executing code that may raise exceptions
TRY
   // Attempt to Ping the client
   IdIcmpClient1.Ping(...);
   EXCEPT // An exception has been raised
   BEGIN
      // Handle this exception
      label1.caption := 'Ping Failiure : ...';
   END;
END;

Alternatively if there is a specific exception that is raised, it is progammatically better to only catch this specific exception, eg EPingViolation :

// Try executing code that may raise exceptions
TRY
   // Attempt to Ping the client
   IdIcmpClient1.Ping(...);
   EXCEPT ON EPingViolation DO
   BEGIN
      // Handle this exception
      label1.caption := 'Ping Failiure : ...';
   END;
END;

Just for interest, as Smurf was saying about the exceptions being raised in the Delphi IDE, even though you have used a try ... except :

This can be prevented by going TOOLS >> DEBUGGER OPTIONS >> LANGUAGE EXCEPTIONS >> ADD ... "EPingViolation"

Delphi will now ignore this exception/error if you use the try ... except statement around the offending code.

Hope this helps,
Steve
0
 
LVL 3

Expert Comment

by:smurff
ID: 8118850
Steve,

>This can be prevented by going TOOLS >> DEBUGGER OPTIONS >> LANGUAGE EXCEPTIONS >> ADD ... "EPingViolation"

Didnt know that thanks ;)

Another point to add about indys ICMP component is that you have to be an administrator user. Not sure why but if this causes you a problem then as Steve said use the ICMP dll. Examples can be found here or at other tips sites such as www.delphi3000.com , www.torry.net etc etc

Regards
Smurff
0
 

Author Comment

by:Stream12
ID: 8142001
Thanks to all.

I didn't know any of the things you guys told me.

I'm gonna try that .dll thing.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question