• 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
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

to exit from a function

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a function (onOk) which calls another function "CommotChanges()" which inturn call another two function. what i need is whenever there is an error in createFolder() function, I want to come out of the "createFolder()" and make sure that the next fucntion (createCustom()) is not called. I want to make sure i roll back the transaction on error.
how can i do that please sugggest

*****************************
onOk()
{
CommitChanges()
}

************************

CommitChanges()
{

beginTrans
try {
createFolder()
createCustom()
createCustom
commit(tans)
}
else {
aborttrans
}
}

createFolder()
{my logic
}

createCustom()
{mylogic
}
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Throw an exception
 
raj kala
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wont throwing of error stop the entire program?
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Throwing exceptions only stops programs if nothing above them in the call stack can handle the exception (and if the current thread is the only active non-daemon thread).

Perhaps just 'return;' would help you.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

wont throwing of error stop the entire program?


No, if you catch it at the appropriate place. For example in the onOk method.
 
reply
    Bookmark Topic Watch Topic
  • New Topic