Skip to content

Commit 2dfd25a

Browse files
author
g.ph
committed
update
1 parent 4bd7e75 commit 2dfd25a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.MD

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,28 @@ func main(){
4141
print(_test.Call('add',1,2))
4242
`)
4343
}
44+
```
45+
46+
47+
### exception
48+
49+
```
50+
51+
func main(){
52+
PyImport_AppendInittab("_test", func() *PyObject {
53+
m := CreateModule("_test", "aa")
54+
m.AddFunction("add", func(a, b int) int {
55+
py3.PyErr_SetString(py3.UserException(),"raise exception")
56+
return a + b
57+
})
58+
return m.AsObj()
59+
})
60+
cpy3.Py_SetProgramName(os.Args[0])
61+
cpy3.Py_SetPythonHome("./")
62+
cpy3.Py_Initialize()
63+
cpy3.PyRun_SimpleString(`
64+
import _test
65+
print(_test.Call('add',1,2))
66+
`)
67+
}
4468
```

0 commit comments

Comments
 (0)