5
Follow an example:
public class Teste
{
public static void main(String[] args)
{
func1();
}
public static void func1()
{
try
{
func2();
}
catch (Exception e)
{
System.err.println("Error 1\n");
}
}
public static void func2()
{
try
{
int x = 1 / 0;
}
catch (Exception e)
{
System.err.println("Error 2\n");
}
}
}
Exit:
Error 2
It is possible to make as soon as the error occurs in func2
he printe Error 2
and triggers this error for the func1
printing Error 1
as in the output example below?
Error 2
Error 1
A doubt, this is just curiosity or do you intend to implement it somewhere?
– user28595
I ask because I see it as a bad practice, the exception is to be used when something unexpected happens. The best is always to try to treat all mistakes, rather than pillage exception upon other.
– user28595
Related reading: How to best treat exceptions in Java?
– user28595
I am studying DB, my class has several functions and all of them have error handling, however in some cases one function calls the other and if the last function gives error there will be problems in some objects at the end
– Iago Coutinho Campos
Even so, this form will complicate you in the future, depending on the complexity. Take a look at the question that Linkei, the post is very enlightening, worthwhile :)
– user28595