H
hardieca
Hi,
I have a custom exception that is not being caught properly. I have
added a reference to a .NET wrapper DLL from HTML Tidy to my project.
When HTML Tidy throws a fatal error, I want my custom exception thrown
and caught so that I may write it so I can write it to a log file. I
am certain everything has been installed correctly, and the program
works beautifully except for the HTML Tidy exceptions not being caught
I am registering the method that throws my custom exception to a
delegate, could that cause issues? The strange thing is when I put a
breakpoint on the line that throws the exception, I can see that it's
being executed. I also see in my output windows that "A first chance
exception of type 'HTMLParser.HTMLParserException' occurred" but it's
not being caught.
The code:
//Simple exception
public class HTMLParserException : ApplicationException
{
public HTMLParserException() { }
public HTMLParserException(string message) : base(message) { }
public HTMLParserException(string message, Exception
innerEx) : base(message, innerEx) { }
}
public class Migrator{
public void TidyDiagnostics(TidyATL.TidyReportLevel level, int line,
int col, string message)
{
//THIS LINE IS EXECUTED WHEN doc.ParseString IS CALLED
throw new
HTMLParser.HTMLParserException(String.Format("{3}: {0} Line: {1}
Col: {2}", message, line, col, level));
}
void tidyUp(string html, string path)
{
Tidy.Document doc = new Tidy.Document();
doc.OnMessage += new
Tidy.IDocumentEvents_OnMessageEventHandler(TidyDiagnostics);
doc.SetOptBool(TidyATL.TidyOptionId.TidyXhtmlOut, 1);
doc.SetErrorFile("c:\\error.txt");
try
{
//ParseString causes an error, TidyDiagnostics is
called
doc.ParseString(html);
doc.CleanAndRepair();
}
catch (Exception e)
{
//THIS PART NEVER GETS EXECUTED
MessageBox.Show(e.Message);
}
Does anyone have any idea?
Thanks,
C.
I have a custom exception that is not being caught properly. I have
added a reference to a .NET wrapper DLL from HTML Tidy to my project.
When HTML Tidy throws a fatal error, I want my custom exception thrown
and caught so that I may write it so I can write it to a log file. I
am certain everything has been installed correctly, and the program
works beautifully except for the HTML Tidy exceptions not being caught
I am registering the method that throws my custom exception to a
delegate, could that cause issues? The strange thing is when I put a
breakpoint on the line that throws the exception, I can see that it's
being executed. I also see in my output windows that "A first chance
exception of type 'HTMLParser.HTMLParserException' occurred" but it's
not being caught.
The code:
//Simple exception
public class HTMLParserException : ApplicationException
{
public HTMLParserException() { }
public HTMLParserException(string message) : base(message) { }
public HTMLParserException(string message, Exception
innerEx) : base(message, innerEx) { }
}
public class Migrator{
public void TidyDiagnostics(TidyATL.TidyReportLevel level, int line,
int col, string message)
{
//THIS LINE IS EXECUTED WHEN doc.ParseString IS CALLED
throw new
HTMLParser.HTMLParserException(String.Format("{3}: {0} Line: {1}
Col: {2}", message, line, col, level));
}
void tidyUp(string html, string path)
{
Tidy.Document doc = new Tidy.Document();
doc.OnMessage += new
Tidy.IDocumentEvents_OnMessageEventHandler(TidyDiagnostics);
doc.SetOptBool(TidyATL.TidyOptionId.TidyXhtmlOut, 1);
doc.SetErrorFile("c:\\error.txt");
try
{
//ParseString causes an error, TidyDiagnostics is
called
doc.ParseString(html);
doc.CleanAndRepair();
}
catch (Exception e)
{
//THIS PART NEVER GETS EXECUTED
MessageBox.Show(e.Message);
}
Does anyone have any idea?
Thanks,
C.