- Home /
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?
Perhaps you're looking for try{ }catch(){}
. Look up try/catch for program$$anonymous$$g.
Answer by ElijahShadbolt · Mar 22, 2018 at 03:50 AM
(untested)
try
{
// open file
}
catch (IOException e)
{
string msg = "Error! " + e.GetType().Name + ": " + e.Message;
// display msg to user
}
Your answer
Follow this Question
Related Questions
Error upon loading assets, Saying access is denied (in my project save location) 1 Answer
Lots of errors after importing john lemon's haunted jaunt package from asset store 0 Answers
Change text gui.button in a for bucle 1 Answer
How to know if the Texture2D.LoadImage succeed in loading 3 Answers
InvalidCastException: Cannot cast from source type to destination type. 1 Answer