-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathJNIException.java
More file actions
29 lines (26 loc) · 1.01 KB
/
JNIException.java
File metadata and controls
29 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.arrayfire;
class JNIException extends Exception {
public JNIException(String message) {
super(message);
}
/**
* Called by native code during construction to set the location.
*/
public void setLocation(String functionName, String file, int line) {
JNIException.addStackTraceElement(this, functionName, file, line);
}
/**
* Pushes a stack trace element onto the existing stack trace of the throwable.
*/
public static void addStackTraceElement(Throwable t, String functionName, String file, int line) {
StackTraceElement[] currentStack = t.getStackTrace();
StackTraceElement[] newStack = new StackTraceElement[currentStack.length + 1];
System.arraycopy(currentStack, 0, newStack, 1, currentStack.length);
file = file.replace('\\', '/');
if (file.lastIndexOf('/') > -1) {
file = file.substring(file.lastIndexOf('/') + 1);
}
newStack[0] = new StackTraceElement("<native>", functionName, file, line);
t.setStackTrace(newStack);
}
}