equal
deleted
inserted
replaced
|
1 /* |
|
2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.microedition.m2g; |
|
19 |
|
20 /** |
|
21 * Class that wraps runnable in order to catch and forward |
|
22 * exceptions that occured when executing in UI thread. |
|
23 * This class is used only for running native methods in UI thread. |
|
24 */ |
|
25 abstract class M2GRunnableQt implements Runnable |
|
26 { |
|
27 private Throwable e = null; |
|
28 |
|
29 /** |
|
30 * From Runnable interface |
|
31 */ |
|
32 public void run() |
|
33 { |
|
34 try |
|
35 { |
|
36 doRun(); |
|
37 } |
|
38 catch (Throwable t) |
|
39 { |
|
40 e = t; |
|
41 } |
|
42 } |
|
43 |
|
44 /** |
|
45 * Checks for possible exceptions and errors and throws them forward. |
|
46 * Only unchecked exceptions and errors are thrown as only checked |
|
47 * exception that m3gcore may throw comes from loader which is not |
|
48 * executed in UI thread |
|
49 * |
|
50 * @throws RuntimeException |
|
51 * @throws Error |
|
52 */ |
|
53 public void checkAndThrow() |
|
54 { |
|
55 if (e == null) |
|
56 { |
|
57 return; |
|
58 } |
|
59 if (e instanceof RuntimeException) |
|
60 { |
|
61 throw(RuntimeException)e; |
|
62 } |
|
63 else if (e instanceof Error) |
|
64 { |
|
65 throw(Error)e; |
|
66 } |
|
67 } |
|
68 |
|
69 /** |
|
70 * Method to be implemented for the UI thead execution |
|
71 */ |
|
72 abstract void doRun(); |
|
73 } |