Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

neglecting an exception

 
feroz muhamed
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
plz help me from this.Is ther any solution to neglect an exception and to execute the rest in the try catch block.
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by feroz muhamed:
hi,
plz help me from this.Is ther any solution to neglect an exception and to execute the rest in the try catch block.

Hi Feroz, What do you mean by neglect??!! if the exception is checked then you MUST catch it with a try-catch block.
 
feroz muhamed
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I 've given the code below.here if the first machine abc is down exception rises and terminates without getting the name of second system which is running.but i need the second either the first is on or off.please help.
code
------------------------------------------------------
import java.net.*;
class forv{
public static void main(String a[])
{
try{
InetAddress i=InetAddress.getByName("abc");
InetAddress i1=InetAddress.getByName("arf");
}catch(UnknownHostException u){
System.out.println("no host "+u.getMessage());
}
}
}
-----------------------------------------------------
 
Ben Poole
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I'm missing something, but what's to stop you placing each connection attempt in its own try catch block?
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by feroz muhamed:
I 've given the code below.here if the first machine abc is down exception rises and terminates without getting the name of second system which is running.but i need the second either the first is on or off.please help.
code
------------------------------------------------------
import java.net.*;
class forv{
public static void main(String a[])
{
try{
InetAddress i=InetAddress.getByName("abc");
InetAddress i1=InetAddress.getByName("arf");
}catch(UnknownHostException u){
System.out.println("no host "+u.getMessage());
}
}
}
-----------------------------------------------------

Then why don't you do what Ben suggested (place each machine in a different try-catch block). It will work that way.
 
feroz muhamed
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi thanks it worked well but the problem is that i am getting the system names using 'net view ' command so i want to do this dynamically(i mean calling getByName("//dynamically changing ")).so making each in separate try catch block is something difficult.plz help if any other soln
 
feroz muhamed
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks i got it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic