# System.err.println()

**URL:** <https://discuss.kotlinlang.org/t/system-err-println/27426>\
**Category:** Language Design\
**Created:** [September 23, 2023, 2:02pm UTC](https://discuss.kotlinlang.org/t/system-err-println/27426 "2023-09-23T14:02:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dhionata](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Dhionata](https://discuss.kotlinlang.org/u/Dhionata)\
**Post date:** [September 23, 2023, 2:02pm UTC](https://discuss.kotlinlang.org/t/system-err-println/27426/1 "2023-09-23T14:02:46Z")

</div>

Why doesn’t Kotlin have something like System.err.Println () Java? I would like to have the option to use in my code, but more simply than Java.

---

<div class="post-metadata">

**Author:** ![al3c](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@al3c](https://discuss.kotlinlang.org/u/al3c)\
**Post date:** [September 23, 2023, 6:10pm UTC](https://discuss.kotlinlang.org/t/system-err-println/27426/2 "2023-09-23T18:10:51Z")

</div>

If you’re targeting the JVM that is actually working in Kotlin as you wrote it

---

<div class="post-metadata">

**Author:** ![Dhionata](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Dhionata](https://discuss.kotlinlang.org/u/Dhionata)\
**Post date:** [September 23, 2023, 7:16pm UTC](https://discuss.kotlinlang.org/t/system-err-println/27426/3 "2023-09-23T19:16:02Z")

</div>

I know so… But Kotlin has its standard for System.out.println() which would just be println(), what I mentioned was just System.err.println(), it could be something like printErrLn(), As if it were something from the Kotlin standard library and not something interoperable with Java.

---

<div class="post-metadata">

**Author:** ![broot](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@broot](https://discuss.kotlinlang.org/u/broot)\
**Post date:** [September 24, 2023, 12:50am UTC](https://discuss.kotlinlang.org/t/system-err-println/27426/4 "2023-09-24T00:50:20Z")

</div>

I don’t know if this is the reason, but maybe authors decided that separate stout and stderr streams are too specific to selected targets only. Almost every runtime has some kind of an output, but not necessarily two of them. But to be honest, I’m not entirely convinced with such explanation myself 🙂

---

<div class="post-metadata">

**Author:** ![gidds](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/gidds/32/10865_2.png) [@gidds](https://discuss.kotlinlang.org/u/gidds)\
**Post date:** [September 25, 2023, 6:47pm UTC](https://discuss.kotlinlang.org/t/system-err-println/27426/5 "2023-09-25T18:47:15Z")

</div>

> [@broot](#):
>
> maybe authors decided that separate stout and stderr streams are too specific to selected targets only

As you say, not overwhelmingly likely — but very possible!

Other possibilities include: not being able to think of a clear, concise name for such a function; wanting to discourage output to stderr as it’s overused; or maybe the language(s) from which they copied println() don’t have an equivalent for stderr (indicating a lack of desire for it)?

But of course, this is all speculation. I’d be interested to hear an official answer.

---

<div class="post-metadata">

**Author:** ![mauricio.guaruja](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@mauricio.guaruja](https://discuss.kotlinlang.org/u/mauricio.guaruja)\
**Post date:** [September 28, 2023, 9:26pm UTC](https://discuss.kotlinlang.org/t/system-err-println/27426/6 "2023-09-28T21:26:37Z")

</div>

> [@Dhionata](#):
>
> Why doesn’t Kotlin have something like System.err.Println () Java? I would like to have the option to use in my code, but more simply than Java.

if this is just about the name you can easily define your function to wrap  
the java code

```auto
fun printErrln(msg: String) {
        System.err.println(msg)
}

```

---

<div class="post-metadata">

**Author:** ![Dhionata](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Dhionata](https://discuss.kotlinlang.org/u/Dhionata)\
**Post date:** [September 29, 2023, 12:15am UTC](https://discuss.kotlinlang.org/t/system-err-println/27426/7 "2023-09-29T00:15:50Z")

</div>

I know I can, but the idea is that there could be a simple line, just like for println() in the standard library.

---

<div class="post-metadata">

**Author:** ![Skaldebane](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/skaldebane/32/11178_2.png) [@Skaldebane](https://discuss.kotlinlang.org/u/Skaldebane)\
**Post date:** [October 1, 2023, 5:56am UTC](https://discuss.kotlinlang.org/t/system-err-println/27426/8 "2023-10-01T05:56:53Z")

</div>

I agree, and I think this extends beyond the JVM. What if I want to print to stderr in Kotlin/Native? That should be possible without dropping down to C.

One good naming scheme may be eprint/ln, as it’s used in some languages like Rust, or maybe errprint/ln which is even more explicit.

---

<div class="post-metadata">

**Author:** ![rebokdev](https://avatars.discourse-cdn.com/v4/letter/r/5daacb/32.png) [@rebokdev](https://discuss.kotlinlang.org/u/rebokdev)\
**Post date:** [October 3, 2023, 4:30pm UTC](https://discuss.kotlinlang.org/t/system-err-println/27426/9 "2023-10-03T16:30:42Z")

</div>

Maybe add optional level parameter(enum) to print and println

something like: println(“An error occured”, OutputLevel.Error)

here’s an example implementation of it(jvm):

```kotlin
fun println(
    message: Any,
    level: OutputLevel = OutputLevel.Standard
) {
    when (level) {
        OutputLevel.Standard -> kotlin.io.println(message)
        OutputLevel.Error -> System.err.println(message)
    }
}

enum class OutputLevel {
    Standard, Error
}

```

---

<div class="post-metadata">

**Author:** ![travisfw](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/travisfw/32/7736_2.png) [@travisfw](https://discuss.kotlinlang.org/u/travisfw)\
**Post date:** [February 11, 2025, 4:44pm UTC](https://discuss.kotlinlang.org/t/system-err-println/27426/10 "2025-02-11T16:44:47Z")

</div>

Bumping after more than a year. There needs to be a multi-platform way of writing to stderr. Standard err is standard. And necessary for writing a tool for the middle of a pipeline. Quick search on [kotlinlang.org](http://kotlinlang.org) shows that [Throwable.printStackTrace()](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/print-stack-trace.html) prints to “standard error output.” How does it do that? Stdlib should all be KMP compatible, right?
