systemml-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luciano Resende <luckbr1...@gmail.com>
Subject Re: incubator-systemml git commit: Better error messages in case of parse errors.
Date Tue, 08 Dec 2015 21:10:38 GMT
On Tue, Dec 8, 2015 at 12:59 PM, <niketanpansare@apache.org> wrote:

> Repository: incubator-systemml
> Updated Branches:
>   refs/heads/master 8c3f97276 -> c27e74547
>
>
> Better error messages in case of parse errors.
>
> @@ -229,7 +230,7 @@ public class DMLParserWrapper extends AParserWrapper
>                         }
>                 }
>                 catch(Exception e) {
> -                       throw new ParseException("ERROR: Cannot parse the
> program:" + fileName);
> +                       throw getParseException(e, "ERROR: Cannot parse
> the program:" + fileName);
>                 }
>
>
> @@ -249,11 +250,26 @@ public class DMLParserWrapper extends AParserWrapper
>                         dmlPgm = createDMLProgram(ast);
>                 }
>                 catch(Exception e) {
> -                       throw new ParseException("ERROR: Cannot translate
> the parse tree into DMLProgram:" + e.getMessage());
> +                       throw getParseException(e, "ERROR: Cannot
> translate the parse tree into DMLProgram");
>                 }
>
>                 return dmlPgm;
>         }
> +
> +       // Alternative is to uncomment the try/catch. But this method is
> preferred as it allows throwing "ParseException" as
> +       // well as providing a given message (such as "Cannot translate
> the parse tree").
> +       private ParseException getParseException(Exception e, String
> message) {
> +               String stackTrace = null;
> +               try {
> +                       PrintWriter printWriter = new PrintWriter(new
> StringWriter());
> +                       e.printStackTrace(printWriter);
> +                       stackTrace = printWriter.toString();
> +               } catch(Exception e1) {}
> +               if(stackTrace != null)
> +                       return new ParseException(message + ":\n" +
> stackTrace);
> +               else
> +                       return new ParseException(message);
> +       }
>
>         private DMLProgram createDMLProgram(DmlprogramContext ast) {
>
>
>
Do we actually want to send the stackTrace as part of the error message ?

What if we could use something like :

throw new ParseException("ERROR: Cannot translate the parse tree into
DMLProgram:" + e.getMessage(), e)

This would not swallow the cause for the error, and
exception.printstacktrace would then have the full stack trace ?

Anyway, just my $ 0.02



-- 
Luciano Resende
http://people.apache.org/~lresende
http://twitter.com/lresende1975
http://lresende.blogspot.com/

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message