История изменений
Исправление crutch_master, (текущая версия) :
и не нужны исключения.
/me закатывает глаза
//java
Class Ret<T> {
private boolean error = false;
private T ret;
public Ret(T default) {
ret = default;
}
public boolean ok() {
return error == false;
}
public Ret<T> err() {
ret = null;
error = true;
return this;
}
public val() {
return ret;
}
public Ret<T> set(T val) {
ret = val;
return this;
}
}
//...
Ret<Integer> someMethod() {
Ret<Integer> ret = new Ret<Integer>(null);
//...
Ret<Long> localVarRaw2 = someMethod2(a1, a2);
if (!localVarRaw2.ok()) return ret.err();
Long localVar2 = localVarRaw2.val();
//...
Ret<String> localVarRaw3 = someMethod3(a1, a2, localVar2);
if (!localVarRaw3.ok()) return ret.err();
Long localVar3 = localVarRaw3.val();
//...
return ret.set(localVar10);
}
Ret<Long> someMethod2() {
Ret<Long> ret = new Ret<Long>(null);
//...
if (allIsBad) return ret.err();
//...
return ret.set(retValue);
}
//etc
Integer someMethod() {
Integer ret = null;
try {
//...
Long localVar2 = someMethod2(a1, a2);
//...
String localVar3 = someMethod3(a1, a2, localVar2);
} catch (Exception e) {
//exception code or another throw
}
return ret;
}
Исходная версия crutch_master, :
и не нужны исключения.
/me закатывает глаза
//java
Class Ret<T> {
private boolean error = false;
private T ret;
public Ret(T default) {
ret = default;
}
public boolean ok() {
return error == false;
}
public Ret<T> err() {
ret = null;
error = true;
return this;
}
public val() {
return ret;
}
public Ret<T> set(T val) {
ret = val;
return this;
}
}
//...
Ret<Integer> someMethod() {
Ret<Integer> ret = new Ret<Integer>(null);
//...
Ret<Long> localVarRaw2 = someMethod2(a1, a2);
if (!localVarRaw2.ok()) return ret.err();
Long localVar2 = localVarRaw2.val();
//...
Ret<String> localVarRaw3 = someMethod3(a1, a2, localVar2);
if (!localVarRaw3.ok()) return ret.err();
Long localVar3 = localVarRaw3.val();
//...
return ret.set(localVar10);
}
Ret<Long> someMethod2() {
Ret<Long> ret = new Ret<Long>(null);
//...
if (allIsBad) return ret.err();
//...
return ret.set(retValue);
}
//etc
Integer someMethod() {
Integer ret = null;
try {
//...
Long localVar2 = someMethod2(a1, a2);
//...
String localVar3 = someMethod3(a1, a2, localVar2);
} catch (Exception e) {
//exception code or another throw
}
return ret;
}