• (disco)

    So TWTF is that it throws a NullReferenceException if message is empty? Seems a bit minor, unless that Conditions thing has some other exception logic.

  • (disco) in reply to JBert

    For those interested: "Geen data om te loggen" can be translated to: "No data to log". which would actually never be reached because the first if statement alters message.

  • (disco) in reply to Dlareg

    Oops it would actually be reached. my bad

  • (disco)

    LogMessageWithArguments("{0}", "") would log an empty message if all those checks weren't there. What's the WTF?

  • (disco) in reply to ChrisH
    ChrisH:
    What's the WTF?
    1. the overload is unnecessary because Log() already has an overload that does formatting
    2. now the log function throws an exception
    3. That exception is a NPE
    4. even if throwing an exception was apropriate there this one should be an ArgumentException because there is no attempt to dereference a null pointer
    5. every item on this list is numbered 42
  • (disco)

    TRWTF is that this is a Remy Porter article and the one HTML comment he added isn't funny.

  • (disco) in reply to accalia
    accalia:
    the overload is unnecessary because `Log()` already has an overload that does formatting
    Then that overload probably does not check if the message is empty. You know, like this function does.
    now the log function throws an exception
    So? We don't know the requirements.
    even if throwing an exception was apropriate there this one should be an ArgumentException because there is no attempt to dereference a null pointer
    Might be excused because they already had special exception handling for NPEs set up and were lazy, but fair enough.
    every item on this list is numbered 42
    Nice.
  • (disco) in reply to ChrisH
    ChrisH:
    Then that overload probably does not check if the message is empty.

    true enough. personally i would expect the behavior that when Log() is called the appropriate logging entry is generated. if i passed an empty string to it then that's my problem Log() should still log it.

    ChrisH:
    We don't know the requirements.
    we never do around these parts. that is our curse, and also our joy. we can argue for **weeks** about what the correct solution should be, regardless of the actual requirements and ignoring other system constraints!
    ChrisH:
    and were lazy
    there is no excuse for lazy.... no excuse at all. :tangerine:
    ChrisH:
    Nice.
    yeah. long standing "bug" that. supposedly it's by design (or rather by spec. Markdown lists define that behavior.)
  • (disco) in reply to ChrisH
    ChrisH:
    >now the log function throws an exception

    So? We don't know the requirements.

    Logging functions throwing is bad, because you can't log it and it means the original log is lost. I've had some nasty problems where I couldn't trace the source of an error until I realised the logging was failing so I was looking in the wrong place

  • (disco) in reply to Jaloopa
    Jaloopa:
    you can't log it and it means the original log is lost.

    Why not? Recursive logging FTW!

    Filed Under: It's logs all the way down!

  • (disco) in reply to Vault_Dweller

    Error: An error was encountered while logging the error

  • (disco) in reply to Jaloopa
    Jaloopa:
    Logging functions throwing is bad, because you can't log it

    Yes, you can! You just need a separate logging framework for logging the failures in logging…

  • (disco) in reply to dkf

    It's logging, all the way down!

  • (disco) in reply to JBert
    JBert:
    So TWTF is that it throws a NullReferenceException if message is empty? Seems a bit minor, unless that Conditions thing has some other exception logic.

    No, the WTF is that it is going to fail if the string is null and the args are not. Sort of half-defensive code. :facepalm:

  • (disco) in reply to Jaloopa

    Error: An error was encountered while encountering an error.

  • (disco) in reply to FullPointerException

    It's yo-dawg-ception for errors!

  • (disco) in reply to CoyneTheDup
    CoyneTheDup:
    JBert:
    So TWTF is that it throws a NullReferenceException if message is empty? Seems a bit minor, unless that Conditions thing has some other exception logic.

    No, the WTF is that it is going to fail if the string is null and the args are not. Sort of half-defensive code. :facepalm:

    I don't get your reply. It does check `args`, and message is reset to the Empty value (which is not null) just before that...
  • (disco) in reply to RFoxmich
    RFoxmich:
    TRWTF is that this is a Remy Porter article and the one HTML comment he added isn't funny
    You're not thinking fourth dimensionally!
  • (disco) in reply to JBert

    Try running string.Format("","This","Will","Totally","Work").

Leave a comment on “Defensive Programming”

Log In or post as a guest

Replying to comment #:

« Return to Article