Hello again,

 

I finally found the solution to this issue.  For the records, I thought I'd
post it up incase anyone else needed to know.

 

This is actually a byproduct of a default profile setting in Visual Studio
2005 and 2008.  There is a feature that allows you to break on exceptions
thrown and handled, regardless if there is a handler to catch the exception
and tell you it was unhandled anyway.  I found some discussion about this at
this page:
http://www.dotnetmonster.com/Uwe/Forum.aspx/vs-net-ide/4729/Disabling-Just-m
y-code-changes-Debug-Exceptions-dialog.

 

This behavior can be disabled two ways:

-          Go to Tools|Options|Debugging|General and uncheck "Enable Just My
Code"

-          Go to Debugger|Exceptions and uncheck "User-handled" in the CLR
row

 

I was also missing the Debugger|Exceptions menu item, which was fixed by
adjusting my profile, which had this option disabled by default.
http://www.williamkent.net/archive/2007/09/12/exception-item-missing-from-my
-vs2005-debug-menu.aspx

 

Once this was sorted out, ANTLR works perfectly when parsing invalid
parser/lexer input.

 

Shawn Poulson

 

 

From: Shawn Poulson [mailto:[EMAIL PROTECTED] 
Sent: Sunday, August 31, 2008 11:28 PM
To: '[EMAIL PROTECTED]'
Subject: C#: Unhandled NoViableAltexception from lexer

 

Hello all,

 

I'm struggling with what appears to be an unexpected behavior in my C# code.
When I attempt to parse a string with my grammar, it works as long as the
input is valid to my parser rules.  When the parser bawks at the input I get
an exception derived from RecognitionException and my code can handle
invalid input.  When the lexer bawks, I usually get a NoViableAltException
thrown that I'm also able to handle.

 

Except, in a specific case my code is unable to handle a
NoViableAltException within a try/catch block.  For example, my grammar does
not utilize semicolons anywhere.  So, if I feed it an input with a semi
anywhere in the input, the lexer will choke and throw a
NoViableAltException, as expected.  For some reason, even if my code
surrounds the ANTLR parser call with a try/catch(Exception) block, the
program execution halts with an unhandled exception.

 

I experienced this with ANTLR 3.0.1, in which case the exception was thrown
from the lexer's mTokens() method.  I noticed ANTLR 3.1 was released
recently, so I gave that a try and used the new CSharp2 target.  I get the
same exact symptom, with the exception being thrown from
Antlr3.Runtime.DFA.Predict().  In both revisions, I've browsed the code
using .NET Reflector and I don't see any funny business going on.  I don't
see any reason why a try/catch block cannot trap this exception!

 

I'm using VS 2008.  I've attempted with .NET 2.0 and .NET 3.5 framework
targets and got the same results.  If necessary, I can send a project that
replicates this issue.

 

Has anyone experienced this before?  Thanks.

 

Shawn Poulson

[EMAIL PROTECTED]


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address

Reply via email to