As part of my question, I would like to include relevant error and/or stack trace information.

How should I format this?

2 Answers 2


First of all, never as an image or screenshot

We build this site for the community, so others can draw benefit from the questions and answers and solutions on the site. For that, everyone needs to be able to find your question (search engines etc.) - and the actual error message you are getting needs to be included in text format for that to happen.

Use a language neutral code block

There are various opinions and approaches to this. For instance, see the discussions here:

The consensus (after a discussion on our Slack community) was: use code blocks, with language formatting turned off.

So a code block, and on the first line, disable language formatting like this:

<!-- language: lang-none -->

It is also possible to surround the error message/stack trace with the <pre></pre> tag blocks.

This renders in the same way as code blocks with language formatting turned off, but possibly slightly easier syntax to remember and without having to indent the original message either (with the 4 spaces required for code blocks).

For example:

Source: .Net SqlClient Data Provider
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)

Using a regular code block, this would trigger C# syntax highlighting (auto detected). The use of the Preformatted Text element forces syntax highlighting to be disabled and the text to be presented exactly as written, including spaces and indentation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .