> For the complete documentation index, see [llms.txt](https://openai.gitbook.io/code-cheatsheets/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openai.gitbook.io/code-cheatsheets/all/scala/exceptions.md).

# exceptions

```scala
def error(msg: String) = throw new Error(msg) 
// (msg: String) => Nothing
throw Exc
```

## Try Catch

```scala
//val result: Int = //an expression so can do this
try {
  remoteCalculatorService.add(1, 2)
} catch {
  case e: ServerIsDownException => log.error(e, "the remote calculator service is unavailable. should have kept your trusty HP.")
} finally {
  remoteCalculatorService.close()
}
```
