3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-09 07:33:24 +00:00

Do not needlessly catch exceptions in Java bindings

A lot of existing code in Java bindings catches exceptions just to
silence them later.

This is:
a) Unnecessary: it is OK for a function to throw a RuntimeException
without declaring it.
b) Highly unidiomatic and not recommended by Java experts (see Effective
Java and others)
c) Confusing as has the potential to hide the existing bugs and have
them resurface at the most inconvenient/unexpected moment.
This commit is contained in:
George Karpenkov 2016-06-12 14:14:11 +02:00
parent 19f98547f7
commit dfc80d3b69
19 changed files with 34 additions and 161 deletions

View file

@ -175,15 +175,8 @@ public class AST extends Z3Object implements Comparable<AST>
* A string representation of the AST. * A string representation of the AST.
**/ **/
@Override @Override
public String toString() public String toString() {
{
try
{
return Native.astToString(getContext().nCtx(), getNativeObject()); return Native.astToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
/** /**

View file

@ -103,14 +103,8 @@ class ASTMap extends Z3Object
**/ **/
@Override @Override
public String toString() public String toString()
{
try
{ {
return Native.astMapToString(getContext().nCtx(), getNativeObject()); return Native.astMapToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
ASTMap(Context ctx, long obj) ASTMap(Context ctx, long obj)

View file

@ -88,15 +88,8 @@ public class ASTVector extends Z3Object
* Retrieves a string representation of the vector. * Retrieves a string representation of the vector.
**/ **/
@Override @Override
public String toString() public String toString() {
{
try
{
return Native.astVectorToString(getContext().nCtx(), getNativeObject()); return Native.astVectorToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
ASTVector(Context ctx, long obj) ASTVector(Context ctx, long obj)

View file

@ -64,15 +64,8 @@ public class ApplyResult extends Z3Object
* A string representation of the ApplyResult. * A string representation of the ApplyResult.
**/ **/
@Override @Override
public String toString() public String toString() {
{
try
{
return Native.applyResultToString(getContext().nCtx(), getNativeObject()); return Native.applyResultToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
ApplyResult(Context ctx, long obj) ApplyResult(Context ctx, long obj)

View file

@ -65,14 +65,8 @@ public class BitVecNum extends BitVecExpr
**/ **/
@Override @Override
public String toString() public String toString()
{
try
{ {
return Native.getNumeralString(getContext().nCtx(), getNativeObject()); return Native.getNumeralString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
BitVecNum(Context ctx, long obj) BitVecNum(Context ctx, long obj)

View file

@ -86,14 +86,8 @@ public class FPNum extends FPExpr
* Returns a string representation of the numeral. * Returns a string representation of the numeral.
*/ */
public String toString() public String toString()
{
try
{ {
return Native.getNumeralString(getContext().nCtx(), getNativeObject()); return Native.getNumeralString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
} }

View file

@ -67,13 +67,7 @@ public class FiniteDomainNum extends FiniteDomainExpr
**/ **/
@Override @Override
public String toString() public String toString()
{
try
{ {
return Native.getNumeralString(getContext().nCtx(), getNativeObject()); return Native.getNumeralString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
} }

View file

@ -254,15 +254,9 @@ public class Fixedpoint extends Z3Object
**/ **/
@Override @Override
public String toString() public String toString()
{
try
{ {
return Native.fixedpointToString(getContext().nCtx(), getNativeObject(), return Native.fixedpointToString(getContext().nCtx(), getNativeObject(),
0, null); 0, null);
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
/** /**

View file

@ -46,14 +46,8 @@ public class FuncDecl extends AST
@Override @Override
public String toString() public String toString()
{
try
{ {
return Native.funcDeclToString(getContext().nCtx(), getNativeObject()); return Native.funcDeclToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
/** /**

View file

@ -211,15 +211,8 @@ public class Goal extends Z3Object
* *
* @return A string representation of the Goal. * @return A string representation of the Goal.
**/ **/
public String toString() public String toString() {
{
try
{
return Native.goalToString(getContext().nCtx(), getNativeObject()); return Native.goalToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
/** /**

View file

@ -63,14 +63,7 @@ public class IntNum extends IntExpr
/** /**
* Returns a string representation of the numeral. * Returns a string representation of the numeral.
**/ **/
public String toString() public String toString() {
{
try
{
return Native.getNumeralString(getContext().nCtx(), getNativeObject()); return Native.getNumeralString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
} }

View file

@ -283,15 +283,8 @@ public class Model extends Z3Object
* @return A string representation of the model. * @return A string representation of the model.
**/ **/
@Override @Override
public String toString() public String toString() {
{
try
{
return Native.modelToString(getContext().nCtx(), getNativeObject()); return Native.modelToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
Model(Context ctx, long obj) Model(Context ctx, long obj)

View file

@ -82,15 +82,8 @@ public class ParamDescrs extends Z3Object
* Retrieves a string representation of the ParamDescrs. * Retrieves a string representation of the ParamDescrs.
**/ **/
@Override @Override
public String toString() public String toString() {
{
try
{
return Native.paramDescrsToString(getContext().nCtx(), getNativeObject()); return Native.paramDescrsToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
ParamDescrs(Context ctx, long obj) ParamDescrs(Context ctx, long obj)

View file

@ -114,14 +114,8 @@ public class Params extends Z3Object
**/ **/
@Override @Override
public String toString() public String toString()
{
try
{ {
return Native.paramsToString(getContext().nCtx(), getNativeObject()); return Native.paramsToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
Params(Context ctx) Params(Context ctx)

View file

@ -52,14 +52,8 @@ public class Pattern extends AST
**/ **/
@Override @Override
public String toString() public String toString()
{
try
{ {
return Native.patternToString(getContext().nCtx(), getNativeObject()); return Native.patternToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
Pattern(Context ctx, long obj) Pattern(Context ctx, long obj)

View file

@ -75,15 +75,8 @@ public class RatNum extends RealExpr
* Returns a string representation of the numeral. * Returns a string representation of the numeral.
**/ **/
@Override @Override
public String toString() public String toString() {
{
try
{
return Native.getNumeralString(getContext().nCtx(), getNativeObject()); return Native.getNumeralString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
RatNum(Context ctx, long obj) RatNum(Context ctx, long obj)

View file

@ -322,15 +322,9 @@ public class Solver extends Z3Object
**/ **/
@Override @Override
public String toString() public String toString()
{
try
{ {
return Native return Native
.solverToString(getContext().nCtx(), getNativeObject()); .solverToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
Solver(Context ctx, long obj) Solver(Context ctx, long obj)

View file

@ -82,15 +82,9 @@ public class Sort extends AST
/** /**
* A string representation of the sort. * A string representation of the sort.
**/ **/
public String toString() @Override
{ public String toString() {
try
{
return Native.sortToString(getContext().nCtx(), getNativeObject()); return Native.sortToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
/** /**

View file

@ -84,15 +84,9 @@ public class Statistics extends Z3Object
/** /**
* The string representation of the Entry. * The string representation of the Entry.
**/ **/
public String toString() @Override
{ public String toString() {
try
{
return Key + ": " + getValueString(); return Key + ": " + getValueString();
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
private boolean m_is_int = false; private boolean m_is_int = false;
@ -118,15 +112,10 @@ public class Statistics extends Z3Object
/** /**
* A string representation of the statistical data. * A string representation of the statistical data.
**/ **/
@Override
public String toString() public String toString()
{
try
{ {
return Native.statsToString(getContext().nCtx(), getNativeObject()); return Native.statsToString(getContext().nCtx(), getNativeObject());
} catch (Z3Exception e)
{
return "Z3Exception: " + e.getMessage();
}
} }
/** /**