You will need to catch and handle that custom exception somewhere. The standard code knows nothing about this and cannot do anything with it. Where you need to handle the exception will very much depend on the structure of your application and what you’re hoping to do with this data. For example, if it’s in an API response, that’s going to be different than on a web page.
Right, but how does the system handle that when it comes to creating the response string that it sends back to the client? I’m not sure I’m explaining this well.
You throw an exception. Various things happen in the code after that. At some point, you send a response (JSON formatted, maybe, or maybe not, you haven’t said, and it doesn’t really matter), presumably with error details in it. You’ve said that you want to inject your additional info into that response, so there must be some response happening, with e.g. your “Connection refused” string in it.
What I’m getting at is how that actual response string is currently being generated. What code (whether yours or a plugin) is mashing together details in the exception to make a string that’s useful to send to the client that made the faulty request? Your changes will need to happen somewhere in that vicinity. Without knowing anything at all about how it’s currently happening, we can’t give any specifics about how to change it.