Exception in Route.handle is handled silently
See original GitHub issueUnhandled 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:
- Created 7 years ago
- Comments:12 (10 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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?I verified this case in our new coroutine-based implementation and everything is good (given CallLogging is installed)