Make my own error message in the statusbar

Hi,

At the line of code that I have marked with an arrow
it gives the actual error in the panel sbMess of a statusbar
but i want to catch the error and display my own text in the
panel of the statusbar?
How can I do that?

Greetings,

Peter Kiers
private void btnInsPmp_Click(object sender, EventArgs e)
        {
            try
            {
                if (System.IO.Directory.GetFiles("I:\\REPORT\\XML", "I*.xml").Length > 0)
                {
                    string[] wholefolder = System.IO.Directory.GetFiles("I:\\REPORT\\XML", "*", System.IO.SearchOption.AllDirectories);
                    foreach (string x in wholefolder)
                    {
                        System.IO.File.Copy(x, "\\XML" + System.IO.Path.GetFileName(x));
                    }
                }
            }
            catch (Exception err)
            {
                sbMess.Caption = (err.Message); <============================
            }
        }

Open in new window

LVL 1
peterkiersAsked:
Who is Participating?
 
AndyAinscowFreelance programmer / ConsultantCommented:
That is just a warning, the compiler realises you have a variable but don't use it in the code anywhere - check warnings and take appropriate action.  In this case just ignore it, you don't want to use the variable.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
sbMess.Caption = "My custom error message goes here";  //(err.Message); <============================
0
 
peterkiersAuthor Commented:
OKe but then I get:
The variable 'err' is declared but never used

P.
0
 
peterkiersAuthor Commented:
Oke. thanks for the info.

Peter
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
ps.
System.IO.File.Copy(x, "\\XML" + System.IO.Path.GetFileName(x));

Is that what you want?  It looks odd to me, check the results of the copying process.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.