hi there, how can i display an error message in java and stop compile program at that point of the error?

Use try catch block for this purpose

Use try catch block for this purpose

how do i do that???

how do i do that???

try{
// code that you want to run
}
catch(NullPointerException nEx){
// what you want it to do or show when a nullpointerexception occurs
}
catch(Exception ex){
// what has to be done in case of another exception
}

a more simple form (the simplest) of this structure is:

try{
// actual code
}
catch(Exception ex){
// what has to be done in case of any exception
}

Be a part of the DaniWeb community

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