Merge pull request #283 from xushiwei/q

setjmp/trycatch
This commit is contained in:
xushiwei
2024-06-08 00:13:06 +08:00
committed by GitHub
8 changed files with 16 additions and 13 deletions

View File

@@ -2,7 +2,7 @@ package main
import ( import (
"github.com/goplus/llgo/c/setjmp" "github.com/goplus/llgo/c/setjmp"
"github.com/goplus/llgo/c/setjmp/demo" "github.com/goplus/llgo/c/setjmp/trycatch"
) )
func main() { func main() {
@@ -10,7 +10,7 @@ func main() {
switch ret := setjmp.Sigsetjmp(&jb, 0); ret { switch ret := setjmp.Sigsetjmp(&jb, 0); ret {
case 0: case 0:
println("Hello, setjmp!") println("Hello, setjmp!")
demo.ThrowCppException() trycatch.ThrowCppException()
setjmp.Siglongjmp(&jb, 1) setjmp.Siglongjmp(&jb, 1)
default: default:
println("exception:", ret) println("exception:", ret)

View File

@@ -1,10 +0,0 @@
extern "C" void throwCppException();
int main() {
try {
throwCppException();
} catch (...) {
throw;
}
return 0;
}

View File

@@ -0,0 +1,13 @@
#include <exception>
#include <stdio.h>
extern "C" void throwCppException();
int main() {
try {
throwCppException();
} catch (std::exception& e) {
printf("Hi, %s\n", e.what());
}
return 0;
}

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package demo package trycatch
import ( import (
_ "unsafe" _ "unsafe"