Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reconsider exception-handlers

See original GitHub issue

Currently, Javalin will only run the closest matching exception handler. From the docs:

app.exception(NullPointerException.class, (e, ctx) -> {
    // handle nullpointers here

app.exception(Exception.class, (e, ctx) -> {
    // handle general exceptions here
    // will not trigger if more specific exception-mapper found

This could be a bit annoying to deal with, especially when developing plugins (as pointed out by @jkschneider in

Should multiple exception handlers be allowed to run per exception?

Should we have something like next()/done() ?

This would be a breaking change, but I guess we could also make it configurable.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

MrThreepwoodcommented, May 21, 2020

For the projects we’ve done we’ve always handled multiple expected exceptions that parse the exception into a specific response and status, and one that is a fall back in case no better exception would be handled (which turns into a 500, sorry something went wrong).

It seems reasonable to think most of these handlers would be handled separately, I would have been very surprised if multiple handlers were called when a specific exception (like Unauthorized) was called. Especially if some of those were expensive. The way I’ve been looking at the exception handlers are: An exception ocurred, decide what response should be sent to the client. It doesn’t really make sense to ask multiple functions what response should be provided, but maybe I’m thinking about them differently than others do?

Maybe it would be easier to have a separate function for registering handlers that should run on all exceptions? Something like app.notifyOnException(Exception.class, (e, ctx) ->{})?

jkschneidercommented, May 24, 2020

I also think that ideally things bound with the current exception() should probably be called after anything bound with this new method?

There are probably cases to suggest this should work both ways. From my perspective as a metrics instrumentation library author, I would prefer listeners to be called after anything that currently implements exception(..). Specifically, this is because my listener would be completing a timing operation on a REST endpoint, and I want to be able to tag this telemetry with the HTTP status code, which can be influenced by a traditional exception handler.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reconsider exception handling concept · Issue #35 · zalando/riptide ...
the general idea should be: pass through everything as-is from custom callbacks/mappers as well as from the underlying RestTemplate; the only case I...
Read more >
Reconsider Flow Error Handling | IdeaExchange
Now the idea: Improve your code to do a null check on Error Id before sending the Exception Email. If an error occured...
Read more >
Exception for In Absentia Removal or Deportation. The filing of a motion to reopen an in absentia order of deportation or removal stays...
Read more >
Parliamentary procedure: What is a motion to reconsider?
To properly handle a motion to reconsider, a member who voted on the prevailing side is recognized by the chair and moves to...
Read more >
Chapter 5 - Appeals, Motions to Reopen, and Motions ... - USCIS
If the appeal relates to a revocation of an approved special immigrant juvenile (SIJ) petition, the appeal must be filed within 15 calendar...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found