提交 d850a570 authored 作者: Thomas Mueller's avatar Thomas Mueller

CREATE ALIAS: error message when compiling Java code have been improved.

上级 7502fbeb
...@@ -119,6 +119,8 @@ public class FunctionAlias extends DbObjectBase { ...@@ -119,6 +119,8 @@ public class FunctionAlias extends DbObjectBase {
javaMethods = new JavaMethod[] { javaMethods = new JavaMethod[] {
method method
}; };
} catch (DbException e) {
throw e;
} catch (Exception e) { } catch (Exception e) {
throw DbException.get(ErrorCode.SYNTAX_ERROR_1, e, source); throw DbException.get(ErrorCode.SYNTAX_ERROR_1, e, source);
} }
......
...@@ -19,6 +19,7 @@ import java.io.PrintWriter; ...@@ -19,6 +19,7 @@ import java.io.PrintWriter;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.HashMap; import java.util.HashMap;
import org.h2.constant.ErrorCode;
import org.h2.message.DbException; import org.h2.message.DbException;
/** /**
...@@ -176,10 +177,8 @@ public class SourceCompiler { ...@@ -176,10 +177,8 @@ public class SourceCompiler {
in.readFully(data); in.readFully(data);
in.close(); in.close();
return data; return data;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw DbException.convert(e);
} finally { } finally {
javaFile.delete(); javaFile.delete();
classFile.delete(); classFile.delete();
...@@ -200,13 +199,18 @@ public class SourceCompiler { ...@@ -200,13 +199,18 @@ public class SourceCompiler {
copyInThread(p.getInputStream(), buff); copyInThread(p.getInputStream(), buff);
copyInThread(p.getErrorStream(), buff); copyInThread(p.getErrorStream(), buff);
p.waitFor(); p.waitFor();
byte[] err = buff.toByteArray(); throwSyntaxError(buff);
if (err.length != 0) {
throw new RuntimeException("Compile error: " + StringUtils.utf8Decode(err));
}
return p.exitValue(); return p.exitValue();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw DbException.convert(e);
}
}
private void throwSyntaxError(ByteArrayOutputStream out) {
String err = StringUtils.utf8Decode(out.toByteArray());
if (err.length() > 0) {
err = StringUtils.replaceAll(err, compileDir, "");
throw DbException.get(ErrorCode.SYNTAX_ERROR_1, err);
} }
} }
...@@ -224,7 +228,7 @@ public class SourceCompiler { ...@@ -224,7 +228,7 @@ public class SourceCompiler {
} }
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw DbException.convert(e);
} }
} }
} .start(); } .start();
...@@ -242,14 +246,9 @@ public class SourceCompiler { ...@@ -242,14 +246,9 @@ public class SourceCompiler {
"-sourcepath", compileDir, "-sourcepath", compileDir,
"-d", compileDir, "-d", compileDir,
javaFile.getAbsolutePath() }); javaFile.getAbsolutePath() });
byte[] err = buff.toByteArray(); throwSyntaxError(buff);
if (err.length != 0) {
throw new RuntimeException("Compile error: " + StringUtils.utf8Decode(err));
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw DbException.convert(e);
} finally { } finally {
System.setErr(old); System.setErr(old);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论