I am a beginner in java and I used Delphi for a long time.
When I want to leave a met开发者_如何学Chod I need to use the exit()
method and in Java I use return
.
To abort all subsequent methods I call the abort()
method in Delphi. How to do this in Java?
There's no direct support in Java for what you're asking, but in a non-elegant way you could simulate abort's behavior by throwing an exception and catching it wherever you see fit in your code.
Using System.exit(0) would not be the same, that method call will exit your program without any chance to recover along the way.
If you use abort like in this link (http://www.delphibasics.co.uk/RTL.asp?Name=Abort), i think this functionality is similar with throw see this link
http://www.roseindia.net/java/exceptions/how-to-throw-exceptions.shtml http://en.wikibooks.org/wiki/Java_Programming/Throwing_and_Catching_Exceptions
精彩评论