公告

大中华汽车电子生态圈社区并入开发者社区- 更多资讯点击此

Tip / 登入 to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

XMC实验分享之五十七: 介绍一个C语言的异常处理机制setjmp/longjmp

XMC实验分享之五十七: 介绍一个C语言的异常处理机制setjmp/longjmp

User12775
Level 5
Level 5
First solution authored First like received

使用过高级语言如C++, Python, Java的程序员对这种异常处理机制应该经常见到:

      FileReader fr = null;        
      try {
         File file = new File("file.txt");
         fr = new FileReader(file); char [] a = new char[50];
         fr.read(a);   // reads the content to the array
         for(char c : a)
         System.out.print(c);   // prints the characters one by one
      } catch (IOException e) {
         e.printStackTrace();
      }finally {
         try {
            fr.close();
         } catch (IOException ex) {        
            ex.printStackTrace();
         }
      }

但是C语言并没有这种try catch的机制, 达到类似的效果, 可以使用

setjmp/longjmp两个函数, 本贴使用xmc1100开发板介绍一下这两个函数.

0 点赞
622 次查看
3 评论