/
KrollExceptionHandler.java
59 lines (56 loc) 路 2.17 KB
/
KrollExceptionHandler.java
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Titanium SDK
* Copyright TiDev, Inc. 04/07/2022-Present
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
package org.appcelerator.kroll;
/**
* <p> An interface for handling exceptions from the runtime. </p>
*
* A KrollExceptionHandler can be registered to the runtime by calling {@link KrollRuntime#setPrimaryExceptionHandler(KrollExceptionHandler)}
* or {@link KrollRuntime#addAdditionalExceptionHandler(KrollExceptionHandler, String)}.<br>
* A handler can either be added as a primary or an additional handler. There can only be one primary handler, while multiple additional handlers can be set.<br>
* When an exception occurs, all of the additional handlers are called first, and the primary handler will be called last.<br>
* By default, the primary handler will be set to a TiExceptionHandler that pops up an error dialog. <br>
*
* <p>An example of performing additional tasks before the default error dialog:</p>
*
* <pre>
* KrollExceptionHandler handler = new KrollExceptionHandler() {
* @Override
* public void handleException(ExceptionMessage arg0) {
* // perform additional tasks here
* }
* };
* KrollRuntime.addAdditionalExceptionHandler(handler, "sampleTask");
* </pre>
*
* To override the default error dialog behavior, simply override the primary handler with a custom handler.
*/
public interface KrollExceptionHandler {
class ExceptionMessage
{
public String title, message, sourceName, lineSource, jsStack, javaStack;
public int line, lineOffset;
public ExceptionMessage(final String title, final String message, final String sourceName, final int line,
final String lineSource, final int lineOffset, final String jsStack,
final String javaStack)
{
this.title = title;
this.message = message;
this.sourceName = sourceName;
this.lineSource = lineSource;
this.line = line;
this.lineOffset = lineOffset;
this.jsStack = jsStack;
this.javaStack = javaStack;
}
}
/**
* Handles the exception
*
* @param e An exception message containing line number, error title, message, etc
*/
void handleException(ExceptionMessage e);
}