mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 18:44:47 +01:00
improve error handling
This commit is contained in:
parent
91ccf92796
commit
fbdd0eb3d0
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 - 2018 Volker Berlin (i-net software)
|
||||
* Copyright 2017 - 2019 Volker Berlin (i-net software)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -71,6 +71,19 @@ public class WasmException extends RuntimeException {
|
||||
lineNumber = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance with a cause.
|
||||
*
|
||||
* @param message
|
||||
* the detail message
|
||||
* @param cause
|
||||
* the cause
|
||||
*/
|
||||
private WasmException( String message, Throwable cause ) {
|
||||
super( message, cause );
|
||||
lineNumber = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a wrapped exception needed.
|
||||
*
|
||||
@ -125,6 +138,22 @@ public class WasmException extends RuntimeException {
|
||||
return new WasmException( cause );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a wrapped exception needed with an additional message.
|
||||
*
|
||||
* @param cause
|
||||
* the wrapped cause
|
||||
* @param message
|
||||
* the message
|
||||
* @return a new instance
|
||||
*/
|
||||
public static WasmException create( String message, Throwable cause ) {
|
||||
if( cause instanceof WasmException ) {
|
||||
return (WasmException)cause;
|
||||
}
|
||||
return new WasmException( message, cause );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line number in Java code on which the error occurred.
|
||||
*
|
||||
|
@ -29,6 +29,7 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import de.inetsoftware.jwebassembly.JWebAssembly;
|
||||
import de.inetsoftware.jwebassembly.WasmException;
|
||||
import de.inetsoftware.jwebassembly.module.FunctionName;
|
||||
import de.inetsoftware.jwebassembly.module.ModuleWriter;
|
||||
import de.inetsoftware.jwebassembly.module.TypeManager.StructType;
|
||||
@ -292,9 +293,14 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
int start = wasm.size();
|
||||
WasmOutputStream stream = new WasmOutputStream();
|
||||
stream.writeVaruint32( size );
|
||||
for( Function func : functions.values() ) {
|
||||
func.addCodeOffset( start + stream.size() );
|
||||
func.functionsStream.writeTo( stream );
|
||||
for( Entry<String, Function> entry : functions.entrySet() ) {
|
||||
try {
|
||||
Function func = entry.getValue();
|
||||
func.addCodeOffset( start + stream.size() );
|
||||
func.functionsStream.writeTo( stream );
|
||||
} catch( RuntimeException ex ) {
|
||||
throw WasmException.create( entry.getKey(), ex );
|
||||
}
|
||||
}
|
||||
wasm.writeSection( SectionType.Code, stream );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user