Skip to content

How catch this error ??

N

Asked Oct 14, 2006, 8:15 AM EDT4 answers
Share
LinkedInX
i use a treeview sample that i have created and want to load the files that i have made
here is an example

C#
void TreeView1AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
string x = e.Node.Text ;

switch(x)
{
case"Node1":

webBrowser1.Navigate (@"\s.html"); ////this works fine

webBrowser2.Navigate (@"\x.html"); ///this works fine too

break;

case"Node2":

webBrowser1.Navigate (@"\s.html"); ////this works fine
webBrowser2.Navigate (@"\x.htmlx"); ///i dont have this file becouse i want to create an error !!
 
i want to catch this error and it must load an empy file of or navigate to ("")
if the file does not exist then dont wat a messagebox with error etc etc...only load an empty file if the file does not exist.visa versa for webbrowser1.navigate(@"\s.html");

break;

}



i can't vigerout how to  solf this problem.
i have try this

if (webbrowser.Document != null)
this does not work becouse it looks only if  document is loaded or not.
i have tryd many if and else statements  and try and catch bloks nothing works.
please help.

thanks

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    use something like the following:

    try
    {

    <Insert your code here. If an exception occurs, then it creates an exception below.>

    }

    Code
    catch (Exception ex)
    {
    MessageBox.Show(Convert.Tostring(ex));
    }
    0
  • 0
    hi
    thanx for jour help but i does not work i stil get an messagebox that says that the file does not exist  en chek it etc etc.
    i want that if a file does not exist that it shows only a blank file or nothing no errors etc etc.

    i have used jour solution  see example below

    try
    {
        webbrowser1.navigate(@"x.htm") ;  ///this file does not exist it only fires an error !!
    }
    Code
    catch (Exception ex)
    {
    MessageBox.Show(Convert.ToString(ex));
    }
    0
  • 0
    The messagebox was there to illustrate that an error has been caught. Remove or comment the messagebox line and you should be Ok.


    try
    {
        webbrowser1.navigate(@"x.htm") ;  ///this file does not exist it only fires an error !!
    }
    Code
    catch (Exception ex)
    {
    //MessageBox.Show(Convert.ToString(ex));
    }
    0
  • 0
    thanx a lott
    it works great ...but.... it can't load the file it wil go on the internet or it shows a file that says that the page does not exist an chek the path etc etc..
    i only wil work offline not to surf the internet !!
    ho do i get a blank page or file  int to the  webbrowser2 if it catches the error ?
    i have tryd this

    try

    {

    webBrowser2.Navigate(@"x.htmx") ; ///this file does not exist it only fires an error !!

    }

    catch

    (Exception ex)

    {

    ////this  should be got to these file but it wont go there

    webBrowser2.Navigate (@"s.html") ;  or webBrowser2.navigate("");

    //MessageBox.Show(Convert.ToString(ex));

    }

    thanx

    0