FAQ
Sorry if this has been asked before, but I am having an issue where I am
trying to use Scanln and create the behavior where if the user simply hits
return without entering any other input a default setting is enabled. There
is an error when this happens which is "unexpected newline". Here is a
code snippet. http://play.golang.org/p/LcNAW52pBl . I realize there may be
a way to ignore the error, but I would like to understand why I am getting
this error and how I could possibly write something like

if err != nil && err != "unexpected newline" {
continue
}

but this does not work. Thanks.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Tomwilde at Mar 3, 2013 at 10:17 pm
    please provide a working playground example.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dave Rose at Mar 4, 2013 at 1:02 am
    This is what I was trying to do Tom. http://play.golang.org/p/PRefCxrOXk

    I am a newbie and still trying to learn why it works as is. I don't
    understand why I simply can not use if err != != "unexpected newline" {
    log.Print(err)
    }

    BUT, that does not work. I thought that the err was a string value. What is
    the difference between err and explicitly stating err.Error() ?

    Thanks,
    Dave
    On Sunday, March 3, 2013 3:17:29 PM UTC-7, tomwilde wrote:

    please provide a working playground example.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dave Rose at Mar 4, 2013 at 1:04 am
    Fixed a small typo
    On Sunday, March 3, 2013 6:02:54 PM UTC-7, Dave Rose wrote:

    This is what I was trying to do Tom. http://play.golang.org/p/PRefCxrOXk

    I am a newbie and still trying to learn why it works as is. I don't
    understand why I simply can not use if err != "unexpected newline" {
    log.Print(err)
    }

    BUT, that does not work. I thought that the err was a string value. What
    is the difference between err and explicitly stating err.Error() ?

    Thanks,
    Dave
    On Sunday, March 3, 2013 3:17:29 PM UTC-7, tomwilde wrote:

    please provide a working playground example.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Sergio Perticone at Mar 4, 2013 at 1:45 pm

    On Mon, Mar 4, 2013 at 2:02 AM, Dave Rose wrote:
    This is what I was trying to do Tom. http://play.golang.org/p/PRefCxrOXk

    I am a newbie and still trying to learn why it works as is. I don't
    understand why I simply can not use if err != != "unexpected newline" {
    log.Print(err)
    }

    BUT, that does not work. I thought that the err was a string value. What is
    the difference between err and explicitly stating err.Error() ?
    http://golang.org/pkg/builtin/#error
    http://golang.org/pkg/builtin/#string
    Thanks,
    Dave
    On Sunday, March 3, 2013 3:17:29 PM UTC-7, tomwilde wrote:

    please provide a working playground example.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Sergio Perticone at Mar 3, 2013 at 11:02 pm

    On Sun, Mar 3, 2013 at 11:06 PM, Dave Rose wrote:
    Sorry if this has been asked before, but I am having an issue where I am trying to use Scanln and create the behavior where if the user simply hits return without entering any other input a default setting is enabled. There is an error when this happens which is "unexpected newline". Here is a code snippet. http://play.golang.org/p/LcNAW52pBl . I realize there may be a way to ignore the error, but I would like to understand why I am getting this error and how I could possibly write something like

    if err != nil && err != "unexpected newline" {
    continue
    }

    but this does not work. Thanks.
    err.Error() != "unexpected newline"

    s.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dave Rose at Mar 4, 2013 at 12:29 am
    Thanks S. That is what I needed.
    On Sunday, March 3, 2013 4:02:18 PM UTC-7, Sergio Perticone wrote:
    On Sun, Mar 3, 2013 at 11:06 PM, Dave Rose wrote:

    Sorry if this has been asked before, but I am having an issue where I am
    trying to use Scanln and create the behavior where if the user simply hits
    return without entering any other input a default setting is enabled. There
    is an error when this happens which is "unexpected newline". Here is a code
    snippet. http://play.golang.org/p/LcNAW52pBl . I realize there may be a
    way to ignore the error, but I would like to understand why I am getting
    this error and how I could possibly write something like
    if err != nil && err != "unexpected newline" {
    continue
    }

    but this does not work. Thanks.
    err.Error() != "unexpected newline"

    s.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 3, '13 at 10:06p
activeMar 4, '13 at 1:45p
posts7
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase