C# throw new exception newline

In my Class file I have a function . I am trying to throw an exception with ("/r/n") (newline) but @ my client the second messsage doesnot appear in newline. I also did try  Environment.Newline but dint work

throw new exception ("Customer exists" + ds.tables(0).row["customer_ID"] + "/r/n" + "PlaceExists")
Result : Place exists should be displayed in next line but it doesnt
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I notice your "\r\n" appears to be the wrong direction, I've used the code bellow sucessfully: -

throw new Exception("This is a test\r\nSecond Line");
Jaime OlivaresSoftware ArchitectCommented:
your code will look more .net stylished like this:
throw new Exception (string.Format("Customer exists {0}\r\nPlaceExists", ds.tables(0).row["customer_ID"]))

dotnet0824Author Commented:
whatz that {0}  why is it used
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

it is a place marker in a format string, the following statment

string.Format("string {0} \r\n line2 {1} \r\n {0)","XYZ","ABC");


line2 ABC
Jaime OlivaresSoftware ArchitectCommented:
It will be useful for more complex exception messages. If you want more information, you can read the help for the String.Format() method.
msg = "\r\n" should work for stand-alone C# apps.
anarki_jimbelSenior DeveloperCommented:
2 jaime_olivares

"your code will look more .net stylished ..."

I'd say, more C++ stylished, isn't it?  :)

By the way, to the question here:
Environment.NewLine works on my computer. And I prefer to use it, not "\r\n"
Jaime OlivaresSoftware ArchitectCommented:
>>your code will look more .net stylished ..."
>>I'd say, more C++ stylished, isn't it?  :)

Don't agree, string.Format() is a .Net library feature, it is not related to any language, could be used in C#, C++.net, vb.net, cobol.net, fortran.net, J#, etc, etc.

Have you tried using single quote?
The hard return is actually only considered one character
Try only adding '\n'

Example "Line 1" + '\n' + "Line 2"
Even this might work Example "Line 1" + '\r' + '\n' + "Line 2"
Jaime OlivaresSoftware ArchitectCommented:
why to do that?
consecutive string concatenation with + operator in .net just make your code slower.
"\r\n" (4 character) is NOT the same as '\r' + '\n' (2 character)

Yes, + operator does take more time but considering this is only for an exception handling process, I don't think creating a StringBuilder is necessary.
Jaime OlivaresSoftware ArchitectCommented:
>>"\r\n" (4 character) is NOT the same as '\r' + '\n' (2 character)
I think you are totally confused about C# escape sequences, "\r\n" is a string with 2 characters, "\\r\\n" is a string with 4 characters.

>>I don't think creating a StringBuilder is necessary.
No, it is not, that's why string.Format() is a better choice.
dotnet0824Author Commented:
Still it dint work... Tried the simplest thing 2 methods given earlier ..
it still prints      "This is a test Second Line "
    protected void Page_Load(object sender, EventArgs e)
        int x;
        x = 0;
            if (x == 0)
              //  throw new Exception("This is a test\r\nSecond Line"); METHOD 1 TRIED
                //throw new Exception(string.Format("This is a test\r\nSecond Line"));  METHOD2 TRIED
        catch (Exception ex)
Jaime OlivaresSoftware ArchitectCommented:
if you are in a web context, \r\n will be unuseful, you should use a <br> tag:

if (x == 0)
    throw new Exception("This is a test<br>Second Line");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Where are you outputing your exception? what format is the text output.
dotnet0824Author Commented:
Thanks it worked out in asp.net
dotnet0824Author Commented:
Thanks it worked out in ASP.NET
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.