#include <stdio.h>

struct A {
    int code;
    A(int c) : code(c) {}
};

void to_reference()
{
    try {
        throw A(42);
    }
    catch (A &ref) {
        printf("A      caught as A&:           code %d\n", ref.code);
    }
}

void to_const_reference()
{
    try {
        throw A(43);
    }
    catch (const A &ref) {
        printf("A      caught as const A&:     code %d\n", ref.code);
    }
}

void pointer_to_const()
{
    char text[] = "from an array";
    try {
        throw text;                     /* type char* */
    }
    catch (const char *s) {
        printf("char*  caught as const char*: %s\n", s);
    }
}

void literal()
{
    try {
        throw "a literal";              /* type const char* */
    }
    catch (char *s) {                   /* skipped: const can't be dropped */
        printf("literal caught as char*: %s\n", s);
    }
    catch (const char *s) {
        printf("literal caught as const char*: %s\n", s);
    }
}

void integers()
{
    try {
        throw 'x';                      /* type char */
    }
    catch (int n) {                     /* skipped: no char -> int */
        printf("char   caught as int: %d\n", n);
    }
    catch (char c) {
        printf("char   caught as char:         %c\n", c);
    }
}

int main()
{
    to_reference();
    to_const_reference();
    pointer_to_const();
    literal();
    integers();
    return 0;
}
