O'Reilly logo

LLVM Cookbook by Suyog Sarda, Mayur Pandey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exception handling in LLVM

In this recipe, we will look into the exception handling infrastructure of LLVM. We will discuss how the exception handling information looks in the IR and the intrinsic functions provided by LLVM for exception handling.

Getting ready...

You must understand how exception handling works normally and the concepts of try, catch and throw and so on. You must also have Clang and LLVM installed in your path.

How to do it…

We will take an example to describe how exception handling works in LLVM:

  1. Open a file to write down the source code, and enter the source code to test exception handling:
    $ cat eh.cpp
    class Ex1 {};
    void throw_exception(int a, int b) {
      Ex1 ex1;
      if (a > b) {
        throw ex1;
      }
    }
    
    int test_try_catch() {
      try {
     throw_exception(2, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required