2

I try to build exception message with 3 lines. But when I try to put Environment.NewLine into the message I get double new line symbol. See the screenshot below.

Double new line symbol

How can I solve the issue?

Serg046
  • 1,043
  • 1
  • 13
  • 42
  • 1
    You can get rid of the "\r"s. – itsme86 Aug 19 '16 at 22:29
  • It doesn't solve the issue. I've already tried '\n'. – Serg046 Aug 19 '16 at 22:31
  • Did you check what you get when this custom exception is catched? What do you do with that message? Do you show it on screen, print, save to file? The point is: the way in which your newlines are handled depend by your output tool. Here, the VS debugger, show the exception in that way, but hardly this is what you get when you run the app outside VS – Steve Aug 19 '16 at 22:36
  • EnvironmentNewLine is greatly overrated. – TaW Aug 19 '16 at 22:39
  • @Steve: it's for debugging purpose. The message contains debug info to quick understand the exception issue. I want to see it in Visual Studio in the realtime. – Serg046 Aug 19 '16 at 22:39
  • I'm not sure how extra line feeds matter when we're in the IDE. Hmm – Xavier J Aug 19 '16 at 23:00
  • @codenoir: we even have the following property - "Debugger.IsAttached" and I use it :-) – Serg046 Aug 19 '16 at 23:06
  • It is a bug. Visual Studio Exception Window duplicates the newlines (even if you copy it to clipboard) – Jan Dec 05 '18 at 14:13

2 Answers2

0

try replace "\r\n" ==> (Environment.NewLine)

alfareed
  • 1
  • 1
  • It doesn't solve the issue. I've already tried. And Environment.NewLine also returns "\r\n" in my Windows machine. – Serg046 Aug 19 '16 at 22:58
0

I think you are asking if you can configure the Visual Studio IDE to display exceptions with single-spaced line breaks in that little window. I don't think it allows that sort of customization. If it really bothers you that much, you can look into Visual Studio extensions.

On a side note, you should consider shortening the exception message. If that much detail is really needed, think about using logging instead.

John Wu
  • 50,556
  • 8
  • 44
  • 80
  • No, I use it with `Debugger.IsAttached` property, just for debug – Serg046 Aug 19 '16 at 23:23
  • Exactly. So why not use [Debugger.Log](https://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.log(v=vs.110).aspx) or [Debug.Write](http://stackoverflow.com/questions/1159755/where-does-system-diagnostics-debug-write-output-appear) if you know you have an output window available? – John Wu Aug 20 '16 at 00:20