Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Managed exception from Python code is always transformed to PythonException #1443

Closed
@tibortakacs

Description

@tibortakacs

Environment

  • Pythonnet version: 3.0.0 preview
  • Python version: 3.8 win32
  • Operating System: Windows
  • .NET Runtime: .NET 5

Summary

If there is a callback from .NET to Python, and the Python code raises a .NET type exception, instead of the corresponding real .NET exception was rethrown on the .NET side (after marshalling), alwaysPython.Runtime.PythonException is thrown.

Details

.NET snippet

classFoo{publicstaticvoidBar(Actionaction){try{action.Invoke();Console.WriteLine("No exception.");}catch(NullReferenceException){Console.WriteLine("Null reference caught.");}catch(Exceptionex){Console.WriteLine("General exception caught: "+ex.GetType().Type);}}}

Python snippet

# .NET importsfromSystemimportNullReferenceException,ActionfromMyProgramimportFoo# Preparationdefcall():raiseNullReferenceException()action=Action(call)# ActionFoo.Bar(action)

Expected output:
Null reference caught.

Actual output:
General exception caught: Python.Runtime.PythonException

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp