• Post Reply Bookmark Topic Watch Topic
  • New Topic

to exit from a function  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Throw an exception
 
raj kala
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wont throwing of error stop the entire program?
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!