can I use the try...catch statement on java to stop the execution of codes on error? just like the exit sub on vb

Recommended Answers

stop the execution of codes on error

It works the opposite way. A catch can allow the program to continue executing when there is an error. Go to this site and read up:
http://docs.oracle.com/javase/tutorial/essential/exceptions/index.html

Jump to Post

The exception will stop the execution of code at the point of the error.
The catch will "catch" the execution and allow the program to continue executing in the catch block's code.

Jump to Post

All 5 Replies

hmmm.. so what statement should I use? coz i'm trying to stop the execution of code when an error occurs

The exception will stop the execution of code at the point of the error.
The catch will "catch" the execution and allow the program to continue executing in the catch block's code.

okay, gonna try it,

but, off course, if you write in your catch-block some statements that will exit the program, you can there end your program any way you want:
displaying a stacktrace
not displaying a stacktrace
giving an error message (popup)
...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.