Python Forum
Catching exceptions in embedded code no longer works on 3.7.2?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Catching exceptions in embedded code no longer works on 3.7.2?
#1
In an older project of mine I used to catch exceptions in the code by doing ...

// simplified code ...
PyObject * PyRes = PyRun_String( ... )
...
PyObject* ex = PyErr_Occurred();
...
if (!PyErr_ExceptionMatches(PyExc_SystemExit))
{
  // there was a non-system error
}
But now I get the error, (in VS2017)

Error:
Error LNK2001 unresolved external symbol PyExc_SystemExit
I suspect i need to include something to my project/files?
Any suggestions as to what might be missing?

Many thanks

FFMG
Reply
#2
exceptions are used in try/except clauses
see: http://openbookproject.net/thinkcs/pytho...tions.html
Reply
#3
(Feb-01-2019, 10:54 PM)Larz60+ Wrote: exceptions are used in try/except clauses
see: http://openbookproject.net/thinkcs/pytho...tions.html

Thanks, but my question was about embedded python code, (in c++), rather than straight Python code.

FFMG
Reply
#4
OK, see that now, I'm an old C++ programmer, but it's been quite a while.
I have to pass.
Reply
#5
I found what the issue is/was

It is a clear case of not reading the manual properly :) ...

In the readme.txt

Quote:Static library
--------------

The solution has no configuration for static libraries. However it is
easy to build a static library instead of a DLL. You simply have to set
the "Configuration Type" to "Static Library (.lib)" and alter the
preprocessor macro "Py_ENABLE_SHARED" to "Py_NO_ENABLE_SHARED". You may
also have to change the "Runtime Library" from "Multi-threaded DLL
(/MD)" to "Multi-threaded (/MT)".
Reply
#6
Thanks for sharing.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 875 Nov-15-2023, 06:56 PM
Last Post: jst
  How to run detectron2, as python embedded code in C++, on GPU? hassaniqbal931 3 1,039 Nov-02-2023, 04:45 PM
Last Post: blabling2
  Code works but doesn't give the right results colin_dent 2 674 Jun-22-2023, 06:04 PM
Last Post: jefsummers
  Beginner: Code not work when longer list raiviscoding 2 764 May-19-2023, 11:19 AM
Last Post: deanhystad
  Code used to work 100%, now sometimes works! muzicman0 5 1,383 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  PiCamera - print exceptions? korenron 2 790 Dec-15-2022, 10:48 PM
Last Post: Larz60+
  a longer docstring Skaperen 8 1,593 Aug-25-2022, 11:21 PM
Last Post: Skaperen
  Class exceptions DPaul 1 1,257 Mar-11-2022, 09:01 AM
Last Post: Gribouillis
  Pyspark - my code works but I want to make it better Kevin 1 1,745 Dec-01-2021, 05:04 AM
Last Post: Kevin
  Catching a crash within a library code ebolisa 9 3,063 Nov-22-2021, 11:02 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020