JetBrains / JetBrains/Exposed

Exception is printed even when exception is caught

Open
#547 12 comments 6 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
9.3k
Forks
798
Avg merge
4d 2h
Merged PRs (30d)
26

Description

So I have a table called User, with it's name column having an UNIQUE-constraint in the database, which defined in the model using .uniqueIndex() method.
You would expect that when I insert an user with a name which already exists like this:
```
addedUser = transaction {
createdUser = transaction {
User {
name = "Someone"
age = 9
}

}
```
, this would result in an exception being raised, like this:
```
org.jetbrains.exposed.exceptions.ExposedSQLException: java.sql.BatchUpdateException: Duplicate entry 'Someone' for key 'Name_UNIQUE'
```

But, when I put a try-catch clause around it like this:

```
try {
createdUser = transaction {
User {
name = "Someone"
age = 9
}
}
}catch (ex : ExposedSQLException){ //Or any other exception instead of ExcposedSQLException, even ex : Exception
println("Caught.")
}
```

, it still prints out this:

```
org.jetbrains.exposed.exceptions.ExposedSQLException: java.sql.BatchUpdateException: Duplicate entry 'Someone' for key 'Name_UNIQUE'
```

My question is: Why does it still print all this rubbish in the console, even though the exception is caught? When I debug and place an breakpoint on the catch clause, the code stops at the breakpoint, which implies the exception has been caught. Still, it prints the whole stacktrace.

I have a feeling it is due to the fact the code snippet which inserts into the database is being invoked by a `suspend fun someFuntion` , but I am not sure.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.