+ 3
How do i call a function when an exception occurs in java
Suppose i want to call a function handleError when i get any exception in code then how do I add it
7 Answers
+ 6
Example:
try{
int a= 5/0;
System.out.print(a);
}
catch (ArithmeticException e){
System.out.print("Arithmetic exception occurs");
}
catch (Exception e){
System.out.print("Error");
}
//You can include catch statements as many as you want.
// A try statement can only execute ONE exception message
https://www.sololearn.com/learn/Java/2175/?ref=app
+ 2
Hmmm you are trying to catch exceptions to build your own errors messages. Firstly you need to explain in what language you wish to do that, the synthax is different following the language.
+ 2
In java
+ 2
Oops, sorry I don't know java. I don't want to missguide you.
+ 2
OK thanks
+ 2
It would be something like this:
try{
//Your Code ...
} catch( Exception e ) {
handleError();
}
+ 1
try...catch