Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java equivalent to php die

I've done some research to know if there is an equivalent to PHP die in java

Sometimes I'm doing small tests and I really want to stop my code at specific line , and return doesnt stop the code like "die" in php

Is there a die quivalent in java?

like image 260
Lamis Avatar asked May 30 '12 07:05

Lamis


People also ask

How do you die in Java?

Use System. exit(0); to exit the java code. Keep a note this will stop the JVM instance which is currently running.

How do you make a die in Javascript?

jQuery die() Method The die() method removes one or more event handlers, added with the live() method, for the selected elements.

What is the use of the die () function?

The die() function prints a message and exits the current script. This function is an alias of the exit() function.

What is the difference between die and echo in PHP?

What is the difference between echo and die() or are they same? The die() function can accept an optional argument string that it will output just before terminating the script. echo() only outputs its arguments, it will not terminate the script.


2 Answers

Use System.exit(0); to exit the java code.

Keep a note this will stop the JVM instance which is currently running.

If you want to come out of a method use return or throw exception to showcase error condition.

like image 92
mprabhat Avatar answered Sep 23 '22 18:09

mprabhat


try:

System.out.println(message);
System.exit(0);
like image 31
Euclides Mulémbwè Avatar answered Sep 25 '22 18:09

Euclides Mulémbwè