• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

exception issues

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Here in the above code i said return ; in calledfunction which throws ScaryException ..

Q1) Whats the use of saying return? What does it return ?Does it return null value ? Even if i wont say return its a feature of java to return back to the calling function na ? then why should i explicitily use return key word there?*/

2.if a try or catch block has a return statement, finally will still run-> flow jumps to the finally then back to the return

can ranchers help me out with a small example for this ?
 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

santosh pilla wrote:
Here in the above code i said return ; in calledfunction which throws ScaryException ..

Q1) Whats the use of saying return? What does it return ?Does it return null value ? Even if i wont say return its a feature of java to return back to the calling function na ? then why should i explicitily use return key word there?*/



return is used to return control, it works same as ending } of a method. No it does not return null. Here explicitly used to confuse programmer only who does not know what will happen when you use return, someone can assume it wrongly that finally will not execute if return is used.

santosh pilla wrote:
2.if a try or catch block has a return statement, finally will still run-> flow jumps to the finally then back to the return

can ranchers help me out with a small example for this ?



Yes you are correct here, here is an example for you, just modify your code and try to understand.


 
santosh pilla
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
where would the return statment in catch block take the control to ?after finally is executed the control goes to return from there ..where the contol goes?
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

santosh pilla wrote:where would the return statment in catch block take the control to ?after finally is executed the control goes to return from there ..where the contol goes?



First JVM sees return in catch, so it jumps to execute finally, after executing finally it executes return.
 
santosh pilla
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats what iam asking ..after return what happens..Where the control will go after return ..what to return ..where to return ?
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Return control to caller method, if main() then return control to JVM.
 
santosh pilla
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jvm means .JVM will take care of it ..right..???thanks punit
 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes,
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic