Grok pattern for java exceptions

As the java exception doesn't log with timestamp. Could you help me on creating grok pattern for it?
All the lines in my log file are similar but I want to parse the logs only when either STUCK or Outofmemory. Could you please help me on this as well?

As the java exception doesn't log with timestamp.

While that might be true in your particular case, exceptions are often logged with whatever logging library is used and so have the same format as other log messages.

Could you help me on creating grok pattern for it?

Please provide an example of what you want to parse.