Skip to content
Snippets Groups Projects
Commit d3a23e92 authored by Drahomír Karchňák's avatar Drahomír Karchňák
Browse files

#434 Sentry now sends IOSExceptions aswell...

parent 9ee399d7
No related merge requests found
......@@ -10,6 +10,8 @@ import com.getsentry.raven.event.Event;
import com.getsentry.raven.event.EventBuilder;
import com.getsentry.raven.event.helper.EventBuilderHelper;
import com.getsentry.raven.event.interfaces.ExceptionInterface;
import com.getsentry.raven.event.interfaces.SentryInterface;
import com.getsentry.raven.event.interfaces.StackTraceInterface;
import net.engio.mbassy.listener.Handler;
......@@ -32,6 +34,13 @@ import cz.nic.tablexia.screen.AbstractTablexiaScreen;
* Created by drahomir on 7/28/16.
*/
public class TablexiaRaven {
private static final String EXCEPTION_TYPE_TAG_NAME = "ExceptionType";
public enum ExceptionType {
JavaException,
IOSException
}
/**
* Custom raven factory which allows to set EventSendFailureCallback
*/
......@@ -203,7 +212,7 @@ public class TablexiaRaven {
Event e = deserializeEvent(file);
if(e != null) {
file.delete();
tablexiaRaven.sentEvent(e);
tablexiaRaven.sendEvent(e);
}
}
}
......@@ -343,11 +352,12 @@ public class TablexiaRaven {
}
}
private void sendExceptionEvent(Thread t, Throwable e) {
private void buildAndSendExceptionEvent(String message, SentryInterface sentryInterface, ExceptionType exceptionType) {
EventBuilder eventBuilder = new EventBuilder()
.withMessage(e.getMessage())
.withSentryInterface(new ExceptionInterface(e))
.withLevel(Event.Level.ERROR);
.withMessage(message)
.withSentryInterface(sentryInterface)
.withLevel(Event.Level.ERROR)
.withTag(EXCEPTION_TYPE_TAG_NAME, exceptionType.toString());
for(Info info : Info.values()) {
info.insert(tablexiaEventBuilderHelper);
......@@ -355,11 +365,19 @@ public class TablexiaRaven {
raven.runBuilderHelpers(eventBuilder);
raven.sendEvent(eventBuilder.build());
Gdx.app.exit();
}
private void sentEvent(Event e) {
private void sendExceptionEvent(Thread t, Throwable e) {
buildAndSendExceptionEvent(e.getMessage(), new ExceptionInterface(e), ExceptionType.JavaException);
}
public static void sendCustomException(ExceptionType exceptionType, String msg, StackTraceElement[] stackTraceElements) {
if(!isStarted()) return;
instance.buildAndSendExceptionEvent(msg, new StackTraceInterface(stackTraceElements), exceptionType);
}
private void sendEvent(Event e) {
if(isStarted() && e != null) instance.raven.sendEvent(e);
}
......
......@@ -5,6 +5,8 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.iosrobovm.IOSApplication;
import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration;
import org.robovm.apple.foundation.NSException;
import org.robovm.objc.block.VoidBlock1;
import org.robovm.apple.foundation.NSAutoreleasePool;
import org.robovm.apple.foundation.NSBundle;
import org.robovm.apple.foundation.NSDictionary;
......@@ -66,10 +68,29 @@ public class IOSLauncher extends IOSApplication.Delegate {
@Override
public boolean didFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) {
boolean result = super.didFinishLaunching(application, launchOptions);
registerUncaughtExceptionHandler();
Gdx.files = tablexiaIOSFiles;
return result;
}
private void registerUncaughtExceptionHandler() {
NSException.setUncaughtExceptionHandler(new VoidBlock1<NSException>() {
@Override
public void invoke(final NSException e) {
String exceptionMsg = e.getName() + ": " + e.getReason();
StackTraceElement[] elements = new StackTraceElement[e.getCallStackSymbols().size()];
for(int i = 0; i < elements.length; i++) {
elements[i] = new StackTraceElement(e.getCallStackSymbols().get(i).toString(), "", "", 0);
}
TablexiaRaven.sendCustomException(TablexiaRaven.ExceptionType.IOSException, exceptionMsg, elements);
}
});
}
public static void main(String[] argv) {
NSAutoreleasePool pool = new NSAutoreleasePool();
UIApplication.main(argv, null, IOSLauncher.class);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment