Question: I typed this into Google, but I only found how-tos in C++.

How can I do it in C?

Answer: 
This question is super old, but I just stumbled across it and thought I'd share a technique: divide by zero, or dereference a null pointer. 

The question is simply "how to throw", not how to catch, or even how to throw a specific type of exception. I had a situation ages ago where we needed to trigger an exception from C to be caught in C++. Specifically, we had occasional reports of "pure virtual function call" errors, and needed to convince the C runtime's \_purecall function to throw something. So we added our own \_purecall function that divided by zero, and boom, we got an exception that we could catch on C++, and even use some stack fun to see where things went wrong.
If you write code with the *[happy path](https://en.wikipedia.org/wiki/Happy_path)* design pattern (for example, for an embedded device) you may simulate exception error processing (AKA deffering or finally emulation) with operator "goto".

```
int process(int port)
{
    int rc;
    int fd1;
    int fd2;

    fd1 = open("/dev/...", ...);
    if (fd1 == -1) {
      rc = -1;
      goto out;
    }

    fd2 = open("/dev/...", ...);
    if (fd2 == -1) {
      rc = -1;
      goto out;
    }

    // Do some with fd1 and fd2 for example write(f2, read(fd1))

    rc = 0;

   out:

    //if (rc != 0) {
        (void)close(fd1);
        (void)close(fd2);
    //}

    return rc;
}

```

It is not actually an exception handler, but it takes you a way to handle error at function exit.

P.S.: You should be careful to use goto only from the same or more deep scopes and never jump a variable declaration.