question-mark
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.

Exception in Route.handle is handled silently

See original GitHub issue

Unhandled exceptions are usually printed (afaik) but the IllegalArgumentException here isnt. My guess would be it should always be printed.

class Blocking(environment: ApplicationEnvironment) : Application(environment) {
    init {
        routing {
            method(HttpMethod.Post){
                route("/exception") {
                    handle {
                        println("exception")
                        throw IllegalArgumentException()
                    }
                }
                route("/exception2") {
                    handle {
                        println("exception2")
                        subject.respondWrite {
                            throw IllegalArgumentException()
                        }
                    }
                }
            }
        }
    }
}

class ExceptionEater {

    @Test
    fun foo(){
        val port = 44003
        val appHostConfig = applicationHostConfig { connector { this.port = port } }
        val appEnv = BasicApplicationEnvironment(javaClass.classLoader, SLF4JApplicationLog("KTorTest"), MapApplicationConfig(
                "ktor.application.class" to Blocking::class.qualifiedName!!
        ))
        val jetty = JettyApplicationHost(appHostConfig, appEnv)
        jetty.start()
        val paths = listOf("exception", "exception2")
        val e = Executors.newCachedThreadPool()
        paths.map { path ->
            e.submit(Callable {
                val c = URL("http://localhost:$port/$path").openConnection() as HttpURLConnection
                c.doOutput = true
                c.outputStream.apply {
                    write("Foo".toByteArray(StandardCharsets.UTF_8))
                    flush()
                }
                c.inputStream.bufferedReader().readLine().apply {
                    println("Done")
                }
            })
        }

        TimeUnit.SECONDS.sleep(10)
    }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
kyegupovcommented, Nov 6, 2016

CallLogger currently does not work as it should: https://github.com/Kotlin/ktor/issues/50

On top of that, swallowing exceptions silently by default is a very bad practice, resulting in an incredibly hostile learning curve.

Perhaps tutorial-mode setups like embeddedJettyServer(routing = ...).start() should have it baked in by default, with logging to stdout/stderr preconfigured?

1reaction
orangycommented, Mar 17, 2017

I verified this case in our new coroutine-based implementation and everything is good (given CallLogging is installed)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Camel aborts route processing silently (no exception, no ...
In cases where I want to skip B I defined it as direct:noop (via a property in a .properties file) with no consumer...
Read more >
Everything you wanted to know about exceptions - PowerShell
To handle a thrown exception, you need to catch it. If an exception is thrown and it isn't caught by something, the script...
Read more >
Exception Handling in Java - Baeldung
Good exception handling can handle errors and gracefully re-route the program to give the user still a positive experience. 2.2. Why Use It?...
Read more >
Chapter 2. Basic Principles of Route Building Red Hat Fuse 7.5
The errorHandler() clause is the original exception handling mechanism provided by Apache Camel and was available before the onException clause was implemented.
Read more >
exception handling in Dart and Flutter - Level Up Coding
It seems that the first definition can include the second one as the unexpected behavior can be one of the reasons why the...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found