How to replace the default error message on view screen

I’m developing a custom field whose data come from a data source like a file. I’d like to show a proper message to user upon creating issues if there is a problem with custom field settings instead of “Error rendering ‘’. Please contact your Jira administrators.” For example when the path to the file enclosing custom field data is wrong.
Currently, I’m throwing exceptions but the result is the same.

Can you please guide me?