• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Return

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try{
fromFile=new FileInputStream(args[0]);
toFile=new toFile(args[1]);
}catch(FilenoutFoundException e){
System.err.println("File could not be copied:" +e);
return;
}
This is an extract from a code.Can somebody clarify the role of return in the catch block
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is not much to say without the context, that is, the method containing this code and the caller method.
The return can be there for multiple reasons. One of them could be that if the source file is not found then the target file won't exist. The method must be stopped if a further proccessing needs to operate on the target file (which doesn't exist) otherwise there may be some weird things happening.
If you have more information about that code excerpt please post it.
 
Tanuja Vaid
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Val,
I just want to know what does the return statement(without any expression) do in a method
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it stops the execution of the current method and returns the control to the caller method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic