use of php.runtime.lang.exception.BaseBaseException in project jphp by jphp-compiler.
the class Environment method catchUncaught.
public boolean catchUncaught(Exception e, boolean retry) {
if (e instanceof UncaughtException)
return catchUncaught((UncaughtException) e);
else if (e instanceof DieException) {
System.exit(((DieException) e).getExitCode());
return true;
} else if (e instanceof ErrorException) {
ErrorException er = (ErrorException) e;
getErrorReportHandler().onFatal(er);
JVMStackTracer tracer = scope.getStackTracer(e);
int i = 0;
for (JVMStackTracer.Item el : tracer) {
if (!el.isInternal()) {
echo("\n\t #" + (i++) + " " + el);
}
}
echo("\n");
for (JVMStackTracer.Item el : tracer) {
if (!el.isSystem()) {
echo("\n\t " + (el.isInternal() ? "" : "->") + " " + el);
}
}
return true;
} else if (e instanceof FinallyException) {
// nop
return true;
} else if (e instanceof BaseBaseException) {
BaseBaseException be = (BaseBaseException) e;
if (exceptionHandler != null) {
try {
exceptionHandler.onException(this, be);
} catch (BaseBaseException _e) {
if (retry) {
throw new RuntimeException(_e);
} else {
catchUncaught(_e, true);
}
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
return true;
} else {
try {
ExceptionHandler.DEFAULT.onException(this, be);
return true;
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
}
} else {
throw new RuntimeException(e);
}
}
use of php.runtime.lang.exception.BaseBaseException in project jphp by jphp-compiler.
the class JvmCompilerCase method check.
public void check(String name, boolean withErrors, int errorFlags) {
File file;
ByteArrayOutputStream outputR = new ByteArrayOutputStream();
Environment environment;
if (isConcurrent()) {
environment = new ConcurrentEnvironment(newScope(), outputR);
} else {
environment = new Environment(newScope(), outputR);
}
//environment.setErrorFlags(ErrorType.E_ALL.value);
Test test = new Test(file = new File(Thread.currentThread().getContextClassLoader().getResource("resources/" + name).getFile()));
Context context = new Context(test.getFile(), file);
try {
JvmCompiler compiler = new JvmCompiler(environment, context, getSyntax(context));
environment.setErrorFlags(0);
if (errorFlags != -1)
environment.setErrorFlags(errorFlags);
if (!isCompiled()) {
environment.setErrorFlags(ErrorType.E_ALL.value);
}
ModuleEntity module = compiler.compile(false);
if (isCompiled()) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
ModuleDumper dumper = new ModuleDumper(context, environment, true);
dumper.save(module, output);
environment.setErrorFlags(ErrorType.E_ALL.value);
module = dumper.load(new ByteArrayInputStream(output.toByteArray()));
}
environment.getScope().loadModule(module);
environment.getScope().addUserModule(module);
environment.registerModule(module);
Memory memory = module.includeNoThrow(environment, environment.getGlobals());
} catch (ErrorException e) {
if (withErrors) {
environment.getErrorReportHandler().onFatal(e);
} else {
throw new CustomErrorException(e.getType(), e.getMessage() + " line: " + (e.getTraceInfo().getStartLine() + test.getSectionLine("FILE") + 2) + ", pos: " + (e.getTraceInfo().getStartPosition() + 1), e.getTraceInfo());
}
} catch (UncaughtException | BaseBaseException e) {
environment.catchUncaught(e);
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
try {
environment.doFinal();
} catch (ErrorException e) {
if (withErrors) {
environment.getErrorReportHandler().onFatal(e);
try {
environment.getDefaultBuffer().flush();
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
} else
throw e;
} catch (RuntimeException e) {
throw e;
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
lastOutput = outputR.toString();
if (test.getExpect() != null)
Assert.assertEquals(test.getTest() + " (" + name + ")", test.getExpect(), rtrim(lastOutput));
if (test.getExpectF() != null) {
Memory result = StringFunctions.sscanf(environment, TraceInfo.valueOf(file.getName(), 0, 0), rtrim(lastOutput), test.getExpectF());
if (result.isNull())
result = new ArrayMemory();
PrintF printF = new PrintF(environment.getLocale(), test.getExpectF(), ((ArrayMemory) result).values());
String out = printF.toString();
Assert.assertEquals(out, rtrim(lastOutput));
}
}
use of php.runtime.lang.exception.BaseBaseException in project jphp by jphp-compiler.
the class Environment method __throwException.
public void __throwException(TraceInfo trace, Memory exception) {
if (exception.isObject()) {
IObject object;
if ((object = exception.toValue(ObjectMemory.class).value) instanceof BaseBaseException) {
__clearSilent();
BaseBaseException e = (BaseBaseException) object;
e.setTraceInfo(this, trace);
throw e;
} else {
triggerError(new FatalException("Exceptions must be valid objects derived from the Exception base class", trace));
}
} else {
triggerError(new FatalException("Can only throw objects", trace));
}
}
use of php.runtime.lang.exception.BaseBaseException in project jphp by jphp-compiler.
the class Environment method catchThrowable.
public static void catchThrowable(Throwable e, Environment environment) {
if (e instanceof BaseBaseException) {
BaseBaseException baseException = (BaseBaseException) e;
baseException.getEnvironment().catchUncaught(baseException);
return;
} else if (e instanceof Exception) {
Environment env = environment == null ? null : environment;
if (env != null) {
try {
env.catchUncaught((Exception) e);
} catch (RuntimeException e2) {
if (env.getDefaultBuffer() == null || env.getDefaultBuffer().getOutput() == null) {
e2.printStackTrace();
} else {
e2.getCause().printStackTrace(new PrintStream(env.getDefaultBuffer().getOutput()));
}
}
return;
}
}
Environment env = environment == null ? null : environment;
if (env != null) {
e.printStackTrace(new PrintStream(env.getDefaultBuffer().getOutput()));
} else {
e.printStackTrace();
}
}
Aggregations