My Java is somewhat rusty and I want to increase the quality of my code. I want to handle expectable errors with exceptions but do not really know how.
I am aware of try catch. But mine always looks like this without any handling:
try { ...}
catch (SQLException e) {
e.printStackTrace();
System.exit(1);
}
I am using Java JDBC with MySQL and I get this concrete error:
com.mysql.jdbc.MysqlDataTruncation: Data truncation:
Data too long for column 'column_name'
It is clear that the value was too large and needs to be truncated. Surely I can check the input before giving it to the database but there might be other errors I also want to handle.
How do I remedy this via exception handling? Is SQLException the right Exception for my error?
There is this duplicate question: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'column_name'. However it does not discuss how to handle it via exceptions.