Is there a syntax highlighting for Java stack traces. Any tips about people editing posts looking at that?
Is there syntax highlighting for Java stack traces? Yes and no.
You can add colour to your stack trace via the features of Google Prettify's standard Java syntax highlighting, which is what Stack Exchange uses. You'll get class and package colour added to your trace but no specific functionality that handles to traces and formats them for reading.
An example of what you can get:
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: /log/t2-console.log (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
How did you do that?
It should just work. But since you're here reading there are two ways to make it kick in:
- Automatically: Tag the question as Java. Stack traces will add some syntax colouring code if there is a Java tag on it.
- Explicitly: If for some reason you wanted it to occur in isolation, maybe without the Java tag or for some other reason it just isn't working, you can explicitly convert your stacktrace into a Java code block.
How do I make it kick-in explicitly? I.e. How do I do section based Java syntax highlighting?
- Indent what you want formatted by four spaces,
- Paste the stack trace, and
- Put one of the following above it with appropriate line breaks and spacing:
<!-- language: lang-java -->
"There's no accounting for taste"
Up to you if you like the colour. I don't mind it but I'm starting to prefer plain text code. I'd prefer something better, something specifically for a trace. But those two options - nothing or something - are what you're going to get for now on SE.
Personally I think it helps to put colour onto the class names and separate out the packages. To me and others it is going to be marginal but I think the benefits are along the lines of what you get when a question is edited for grammar. It can help more quickly identify the class, package or module that a problem is based within. It's something Eclipse and IntelliJ have seen fit to add. IMO if that makes the question and answer more useful, that's probably going to be a good thing. However, as I said, it's up to your taste but all you get is something or nothing.
More on the No part of this answer
"If prettify doesn't have it, neither do we."
As I alluded to, I don't think this is an intentional feature and as mentioned in the comments here, stack traces here are often left as plain text. If it's something you're keenly interested in, something you'd like to see brought into Stack Exchange or something you'd like to work on Prettify is a good place to start. If nothing else, it could be a good open-source project.
There are a few discussions on features of syntax highlighting on Stack Exchange if you look at the related questions area to the right of the question/answer here. The commonly directed one that is most commonly thrown up is "There's a bug in the syntax highlighting".