Your code should be always prepared for getting an error from the database during an insert operation, and to display a useful error message in this case. Hence "either - or" is the wrong question: you should ask if it makes sense to validate the string length prior to inserting additionally.
However, when you insert a lot of columns in one transaction, checking the string length beforehand could make it simpler to find out which of the many columns might violate a length constraint. If that's what you are trying to accomplish, I would recommend to make sure your application retrives the string length either directly from the database schema (for example, once when the program starts, querying the related schema tables), or the schema as well as the application code try to use a "single source of truth" for the maximum string length.
Which of these alternatives you pick depends heavily on how much effort it is in your system to retrieve schema information, how the schema is created or generated, how the database layer is created or generated, and how this looks in relationship to the alternative of getting the affected column name and allowed string length out of a "constraint-violated message" from the DB.
Another thing to consider is how your database schema is maintained:
- Does your team have a development process which makes sure your DB schema stays backwards compatible? And do you have a quick update process for your application in case a user notices an error?
If the answers are yes and yes, you may simply live with the risk of getting an inconsistency here.