Answer the question
In order to leave comments, you need to log in
How to avoid premature optimization? Or how, not knowing what will happen later in the project, handle exceptions?
void fun()
{
int a = div(4,6); // внешний код, не будет знать как-там что проиошло, но может когда-то знахочет знать
}
int div(int x,int y)
{
try
{
return x / y;
}catch(Exception ex)
{
return 0; // вот тут потеря информации. К примеру сейчас мне всю-равно.
//А вдруг потом при обновлении, мне понадобится
// извлечь сообщение, и сохранить значения Х,У допустим.
}
Answer the question
In order to leave comments, you need to log in
If you can’t change the code later, well, I don’t know, you cast it in stone and launched it to the moon and you don’t want to be embarrassed in front of your grandchildren, then do everything at once and for centuries. The rest of the people have no problem releasing version 1.1
Interfaces
were invented for your situation .
Look, there is an output logic (Kotlin, I hope it is clear what this code does):
interface Report {
fun getAverageTime(): BigDecimal
}
fun printReport(report: Report) {
println("Average time: ${report.getAverageTime()}")
}
interface Report {
fun getAverageTime(): BigDecimal
fun getCountWithZeroTime(): Int
}
fun printReport(report: Report) {
println("Average time: ${report.getAverageTime()}")
println("Participants have zero-time: ${report.getCountWithZeroTime()}")
}
if it seems to me that the information about ignoring is useful when debugging,
I write the output to the debug console in the ketch.
If you are 100 percent sure that it will not help later in the analysis, then
try{
// actions
return an honest result
}catch(Exception ignored){}
return the default value
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question