How can I detect error messages in-game?

I’m developing a program which loads files from somewhere on the user’s hard drive. Occasionally while using it, the following error occurs:

**IOException: Sharing violation on path **

Now, I know why this error occurs. It happens whenever the user already has the file open in another program. The problem is that I need to convey to the user exactly what happened.

Ideally, I’d like to make a check when loading the file. If this error is detected, then I’d like to have a Text object display a message like “Error: Cannot load file. File is already open in another program.” That said, I don’t know how to check for the case where this specific error message pops up. How would it be possible for me to do so?


    // open file
catch (IOException e)
    string msg = "Error! " + e.GetType().Name + ": " + e.Message;
    // display msg to user