diff --git a/src/main/java/org/sablecc/sablecc/lexer/Lexer.java b/src/main/java/org/sablecc/sablecc/lexer/Lexer.java
index c38142abd0ab59a90dc6849b637833b758bb01b7..699b889a94b1fe19afa5f65c9b88599c8207bcb2 100644
--- a/src/main/java/org/sablecc/sablecc/lexer/Lexer.java
+++ b/src/main/java/org/sablecc/sablecc/lexer/Lexer.java
@@ -176,7 +176,7 @@ public class Lexer
                     case -1:
                         if(this.text.length() > 0)
                         {
-                            throw new LexerException("[" + (startLine + 1) + "," + (startPos + 1) + "] Unknown token: " + this.text);
+                            throw new LexerException(startLine + 1, startPos + 1, "Unknown token: " + this.text);
                         }
 
                         return new EOF(startLine + 1, startPos + 1);
@@ -350,7 +350,7 @@ public class Lexer
                         break;
 
                     default:
-                        throw new LexerException("[" + (startLine + 1) + "," + (startPos + 1) + "] Internal lexer error: invalid accept table entry " + acceptToken + ", current text: " + this.text);
+                        throw new LexerException(startLine + 1, startPos + 1, "Internal lexer error: invalid accept table entry " + acceptToken + ", current text: " + this.text);
                 }
                 pushBack(acceptLength);
                 this.pos = acceptPos;
diff --git a/src/main/java/org/sablecc/sablecc/lexer/LexerException.java b/src/main/java/org/sablecc/sablecc/lexer/LexerException.java
index 9ae73de75599db94002bc36552904cd6cd2b6adf..ff4967e996b54a6bdc34a5de61e6d91ae1846522 100644
--- a/src/main/java/org/sablecc/sablecc/lexer/LexerException.java
+++ b/src/main/java/org/sablecc/sablecc/lexer/LexerException.java
@@ -5,8 +5,35 @@ package org.sablecc.sablecc.lexer;
 @SuppressWarnings({"serial"})
 public class LexerException extends Exception
 {
+    private final int line;
+    private final int pos;
+    private final String realMsg;
+
+    public LexerException(int line, int pos, String message)
+    {
+        super("[" + line + "," + pos + "] " + message);
+        this.line = line;
+        this.pos = pos;
+        this.realMsg = message;
+    }
+
     public LexerException(String message)
     {
-        super(message);
+        this(0, 0, message);
+    }
+
+    public int getLine()
+    {
+        return this.line;
+    }
+
+    public int getPos()
+    {
+        return this.pos;
+    }
+
+    public String getRealMsg()
+    {
+        return this.realMsg;
     }
 }
diff --git a/src/main/resources/org/sablecc/sablecc/lexer.txt b/src/main/resources/org/sablecc/sablecc/lexer.txt
index c877b18803adbde214f1aeb8ac1584b94194fd03..aa9b584888e26addfee5c861eb2096fd167b09fa 100644
--- a/src/main/resources/org/sablecc/sablecc/lexer.txt
+++ b/src/main/resources/org/sablecc/sablecc/lexer.txt
@@ -13,9 +13,36 @@ package $0$lexer;
 @SuppressWarnings({"serial"})
 public class LexerException extends Exception
 {
+    private final int line;
+    private final int pos;
+    private final String realMsg;
+
+    public LexerException(int line, int pos, String message)
+    {
+        super("[" + line + "," + pos + "] " + message);
+        this.line = line;
+        this.pos = pos;
+        this.realMsg = message;
+    }
+
     public LexerException(String message)
     {
-        super(message);
+        this(0, 0, message);
+    }
+
+    public int getLine()
+    {
+        return this.line;
+    }
+
+    public int getPos()
+    {
+        return this.pos;
+    }
+
+    public String getRealMsg()
+    {
+        return this.realMsg;
     }
 }
 
@@ -200,7 +227,7 @@ public class Lexer
                     case -1:
                         if(this.text.length() > 0)
                         {
-                            throw new LexerException("[" + (startLine + 1) + "," + (startPos + 1) + "] Unknown token: " + this.text);
+                            throw new LexerException(startLine + 1, startPos + 1, "Unknown token: " + this.text);
                         }
 
                         return new EOF(startLine + 1, startPos + 1);
@@ -244,7 +271,7 @@ $
 
 Macro:LexerBody
                     default:
-                        throw new LexerException("[" + (startLine + 1) + "," + (startPos + 1) + "] Internal lexer error: invalid accept table entry " + acceptToken + ", current text: " + this.text);
+                        throw new LexerException(startLine + 1, startPos + 1, "Internal lexer error: invalid accept table entry " + acceptToken + ", current text: " + this.text);
                 }
                 pushBack(acceptLength);
                 this.pos = acceptPos;