[Ironpython-users] Unhandled .Net Exception

John Dickinson jhcd.jhcd at gmail.com
Tue Oct 25 12:33:21 CEST 2011


Thanks Dino, that's exactly what I wanted!

On Mon, Oct 24, 2011 at 6:16 PM, Dino Viehland <dinov at microsoft.com> wrote:

>  This should do it – the hosting APIs changed quite a bit between 2.0 and
> 2.7:****
>
> import clr****
>
> clr.AddReference('IronPython')****
>
> from IronPython.Runtime import PythonContext****
>
> import System****
>
>
> clr.GetCurrentRuntime().GetLanguage(PythonContext).FormatException(System.Exception())
> ****
>
> ** **
>
> There could be other variations such as using GetLanguageByExtension and
> not needing to add a ref to IronPython but those will require that the
> script runtime has the languages properly registered.****
>
> ** **
>
> *From:* ironpython-users-bounces+dinov=exchange.microsoft.com at python.org[mailto:
> ironpython-users-bounces+dinov=exchange.microsoft.com at python.org] *On
> Behalf Of *John Dickinson
> *Sent:* Monday, October 24, 2011 9:52 AM
> *To:* ironpython-users at python.org
> *Subject:* [Ironpython-users] Unhandled .Net Exception****
>
> ** **
>
> Hello, I was looking at adding a handler for otherwise-uncaught .Net
> exceptions, and had found this page:
> http://www.ironpython.info/index.php/Handling_Unhandled_Exceptionsuseful. However, the code shown falls over where he's trying to get a
> nicely formatted python exception here:****
>
>     from IronPython.Hosting import PythonEngine****
>
>     pyE = PythonEngine()****
>
>     print pyE.FormatException(event.Exception)****
>
> where I get "ImportError: No module named Hosting". At the bottom he has a
> note saying:****
>
> "For IronPython 2.0, the code to format the exception from a PythonEngine
> is slightly different: ****
>
> import clr****
>
> clr.AddReference('IronPython')****
>
> from IronPython.Hosting import PythonEngine****
>
> PythonEngine.CurrentEngine.FormatException(someException)****
>
> "
>
> which gives me "ImportError: Cannot import name PythonEngine".
>
> I'm using IronPython 2.7.0.40 with .Net 4.0.30319.239. I assume the API
> has changed here; can anyone tell me if there is a way to do something like
> this FormatException in IronPython 2.7?
>
> Thanks.****
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20111025/001a7645/attachment.html>


More information about the Ironpython-users mailing list