Following the course on exceptions, where i explain that a catch() is an 
instanceof,
two different students ask me why catch() can use '|' in between the exception 
types but instanceof can not.

i.e why this code works
  try {
    ...
  } catch(RuntimeException | Error e) {
    throw e;
  } catch(Throwable t) {
    ...
  }

but this one doesn't
  try {
    ...
  } catch(Throwable t) {
    if (t instanceof RuntimeException | Error e) {
      throw e;
    }
    ...
  }

I wonder if people will want to do pattern matching on exceptions ?

Rémi

Reply via email to