473,224 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

ironpython exception line number


Hello ,

When an exeption occurs in a IronPython executet script, and I print the
sys.exc , i get something ugly like the example below.
How can I get the fileName and line number?

Thx in advance
Troels
26-06-2007 13:19:04 : IronPython.Runtime.Exceptions.PythonIndentationErr or:
unexpected token def
ved IronPython.Compiler.SimpleParserSink.AddError(Stri ng path, String
message, String lineText, CodeSpan span, Int32 errorCode, Severity severity)

ved IronPython.Compiler.CompilerContext.AddError(Strin g message, String
lineText, Int32 startLine, Int32 startColumn, Int32 endLine, Int32
endColumn, Int32 errorCode, Severity severity)

ved IronPython.Compiler.Parser.ReportSyntaxError(Locat ion start, Location
end, String message, Int32 errorCode)
ved IronPython.Compiler.Parser.ReportSyntaxError(Token t, Int32
errorCode, Boolean allowIncomplete)
ved IronPython.Compiler.Parser.ParseSuite()
ved IronPython.Compiler.Parser.ParseFuncDef()
ved IronPython.Compiler.Parser.ParseStmt()
ved IronPython.Compiler.Parser.ParseSuite()
ved IronPython.Compiler.Parser.ParseClassDef()
ved IronPython.Compiler.Parser.ParseStmt()
ved IronPython.Compiler.Parser.ParseFileInput()
ved IronPython.Hosting.PythonEngine.Compile(Parser p, Boolean
debuggingPossible)
ved IronPython.Hosting.PythonEngine.CompileFile(String fileName)
ved IronPython.Hosting.PythonEngine.ExecuteFile(String fileName)

Jun 26 '07 #1
2 5580
Given a file foo.py:

def f():

You should get these results:

IronPython 1.0.60816 on .NET 2.0.50727.312
Copyright (c) Microsoft Corporation. All rights reserved.
>>try:
.... execfile('foo.py')
.... except IndentationError, e:
.... import sys
.... x = sys.exc_info()
....
>>print x[1].filename, x[1].lineno, x[1].msg, x[1].offset, x[1].text, x[1].args
foo.py 2 unexpected token <eof1 ('unexpected token <eof>', ('foo.py', 2,1, ''))
>>>
Which is very similar to the result you get from CPython although we seem to disagree about what we expect next.

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>try:
.... execfile('foo.py')
.... except IndentationError, e:
.... import sys
.... x = sys.exc_info()
....
>>print x[1].filename, x[1].lineno, x[1].msg, x[1].offset, x[1].text, x[1].args
foo.py 2 expected an indented block 9 ('expected an indented block', ('foo..py', 2, 9, ''))
>>^Z

If you're hosting IronPython and catching this from a .NET language then you'll be catching the .NET exception. In that case you can access the original Python exception from ex.Data["PythonExceptionInfo"]. Alternately you could catch PythonSyntaxErrorException and access its properties (Line, Column, FileName, LineText, Severity, and ErrorCode).

-----Original Message-----
From: py*************************************@python.org [mailto:py*************************************@pyt hon.org] On Behalf Of Troels Thomsen
Sent: Tuesday, June 26, 2007 1:33 PM
To: py*********@python.org
Subject: ironpython exception line number
Hello ,

When an exeption occurs in a IronPython executet script, and I print the
sys.exc , i get something ugly like the example below.
How can I get the fileName and line number?

Thx in advance
Troels
26-06-2007 13:19:04 : IronPython.Runtime.Exceptions.PythonIndentationErr or:
unexpected token def
ved IronPython.Compiler.SimpleParserSink.AddError(Stri ng path, String
message, String lineText, CodeSpan span, Int32 errorCode, Severity severity)

ved IronPython.Compiler.CompilerContext.AddError(Strin g message, String
lineText, Int32 startLine, Int32 startColumn, Int32 endLine, Int32
endColumn, Int32 errorCode, Severity severity)

ved IronPython.Compiler.Parser.ReportSyntaxError(Locat ion start, Location
end, String message, Int32 errorCode)
ved IronPython.Compiler.Parser.ReportSyntaxError(Token t, Int32
errorCode, Boolean allowIncomplete)
ved IronPython.Compiler.Parser.ParseSuite()
ved IronPython.Compiler.Parser.ParseFuncDef()
ved IronPython.Compiler.Parser.ParseStmt()
ved IronPython.Compiler.Parser.ParseSuite()
ved IronPython.Compiler.Parser.ParseClassDef()
ved IronPython.Compiler.Parser.ParseStmt()
ved IronPython.Compiler.Parser.ParseFileInput()
ved IronPython.Hosting.PythonEngine.Compile(Parser p, Boolean
debuggingPossible)
ved IronPython.Hosting.PythonEngine.CompileFile(String fileName)
ved IronPython.Hosting.PythonEngine.ExecuteFile(String fileName)

--
http://mail.python.org/mailman/listinfo/python-list
Jun 28 '07 #2
>If you're hosting IronPython and catching this from a .NET language
then you'll be catching the .NET exception.
Yes
>In that case you can access the original Python exception
from ex.Data["PythonExceptionInfo"].
Yes ! YES !
Thx

regards tpt
Jun 30 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: srijit | last post by:
Hello, Here is an example code of xml writer in Python+PythonNet, Ironpython and Boo. The codes look very similar. Regards, Srijit Python + PythonNet: import CLR
3
by: Carl Johan Rehn | last post by:
What is the difference between CPython, Python for .NET, and IronPython? For example, if I'm running IronPython, can I access modules such as Numeric and numarray? As I understand it,...
3
by: Sanghyeon Seo | last post by:
I took some time to write this HOWTO: http://sparcs.kaist.ac.kr/~tinuviel/fepy/howto/simplehttpserver-ironpython-mono-howto.html IronPython seems to get much less interest than it deserves. This...
7
by: sanxiyn | last post by:
Skip wrote: For those of us who have never used IronPython or Mono, is there a quick start document laying about somewhere? It wasn't clear to me where to even look. Okay, here we go: 1....
9
by: Claudio Grondi | last post by:
(just wanted to share my experience with IronPython 1.0) The context: C:\IronPythonipy.exe IronPython 1.0.60816 on .NET 2.0.50727.42 Copyright (c) Microsoft Corporation. All rights reserved....
1
by: edfialk | last post by:
Hi all, I'm completely new to Python, but fairly experienced in PHP and few other languages. Long story short: The IronPython executable doesn't work for .cgi scripts in my browser. I've...
1
by: Divya | last post by:
Hello, I'm new to IronPython and COM so please bear with me. I have a COM interface provided to me. I need to implement this interface and pass it to a method as a way of implementing...
3
by: Jack | last post by:
I learned a lot from the other thread 'Is a "real" C-Python possible?' about Python performance and optimization. I'm almost convinced that Python's performance is pretty good for this dynamic...
0
by: mindmind | last post by:
> I had it running through the night, ~100 times, 25 of these gave the above exception. Hard to see any pattern.
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.