• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

output of this program?

 
Anto Telvin
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
i have the following code i want to know what is happening after try is executed where the control will go after reaching return.

class exception
{
public static void main(String args[])
{
System.out.println("A");
try
{
return;
}
catch(Exception e)
{
System.out.println("B");
}
System.out.println("C");
}
}
thanks
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried it? What happened?
 
Anto Telvin
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried but it is printing only A that means control is moving out of the class is it like that or else and why it is not printing C
[ October 23, 2008: Message edited by: Anto Telvin ]
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and why it is not printing C


What makes you think that it would print C? return statement is not like throwing an Exception. It transfers the control out of the method.
 
Anto Telvin
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup i got thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anto, you've been asked this before, but I'll repeat: please Use Code Tags. It really makes a difference.
 
Anoobkumar Padmanabhan
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anto,

But if you put the print statement for C in a finally block, this will display. Am I right??
 
Henry Wong
author
Marshal
Pie
Posts: 21185
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if you put the print statement for C in a finally block, this will display. Am I right??


Well, what happened when you tried it?

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic