-3

I'm using Java and have a function like this:

public date verifDate(date){
    Date dateActuelle = new Date();     
    if (DateUtils.getDateAddDays(date, 1).after(dateActuelle)) {
        return date;
    } else {
        //exit
    }

I want to get out of the function and not continue the rest of the program.

Ben the Coder
  • 539
  • 2
  • 5
  • 21
josef
  • 89
  • 2
  • 9
  • 1
    If you want to end the function, you need to `return` from it. To exit the whole program, you can use [`System.exit`](https://docs.oracle.com/javase/8/docs/api/java/lang/System.html#exit-int-) if that's really what you want. – khelwood Mar 22 '17 at 12:25
  • return null; this will help you – Pratik Ambani Mar 22 '17 at 12:26
  • You have to return a date object if your method signature says that the method returns one. You can of course also throw an Exception. – OH GOD SPIDERS Mar 22 '17 at 12:26
  • @khelwood i don't exit the whole program! i want to stop the precessing of the rest of the program and start again – josef Mar 22 '17 at 12:34
  • 2
    So where your question says "don't continue processing the rest of the program", you meant something different? – khelwood Mar 22 '17 at 12:34
  • @khelwood i mean just i said in the last comment : stop the precessing of the rest of the program and start again without stopping the server – josef Mar 22 '17 at 12:36
  • you can use `break` but that is considered bad programming, one other thing you can do is to have a boolean variable and every time the else part is executed change the value of the boolean variable and then you can have an if statement checking for boolean value. This is just off the top of my mind. Will need to look at your question once i get home. – Saad Mar 22 '17 at 12:47

1 Answers1

0

Calling this will kill the JVM:

System.exit(0);
Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • Small caveat: It is possible that security has been added to the JVM to prevent this, however if this is your program, that won't be the case. – Bohemian Mar 22 '17 at 12:27
  • 1
    Is the OP not supposed to return an object? `System.exit(0)` will terminate his whole program. BTW i did not down-vote your answer. – Saad Mar 22 '17 at 12:42
  • @saad that is the only option given the question, although it is interesting that this answer was downvoted, but the other near identical answer (and near identical timestamp) was upvoted. – Bohemian Mar 22 '17 at 12:55