{
return new BigInteger(str.substring(HEX_PREFIX.length()), HEX_RADIX);
}
catch (NumberFormatException nex)
{
throw new ConversionException("Could not convert " + str
+ " to " + targetClass.getName()
+ "! Invalid hex number.", nex);
}
}
if (str.startsWith(BIN_PREFIX))
{
try
{
return new BigInteger(str.substring(BIN_PREFIX.length()), BIN_RADIX);
}
catch (NumberFormatException nex)
{
throw new ConversionException("Could not convert " + str
+ " to " + targetClass.getName()
+ "! Invalid binary number.", nex);
}
}
try
{
Constructor<?> constr = targetClass.getConstructor(CONSTR_ARGS);
return (Number) constr.newInstance(new Object[]{str});
}
catch (InvocationTargetException itex)
{
throw new ConversionException("Could not convert " + str
+ " to " + targetClass.getName(), itex
.getTargetException());
}
catch (Exception ex)
{
// Treat all possible exceptions the same way
throw new ConversionException(
"Conversion error when trying to convert " + str
+ " to " + targetClass.getName(), ex);
}
}
}