javauis/m2g_qt/javasrc/com/nokia/microedition/m2g/M2GRunnableQt.java
changeset 80 d6dafc5d983f
parent 56 abc41079b313
child 87 1627c337e51e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/javauis/m2g_qt/javasrc/com/nokia/microedition/m2g/M2GRunnableQt.java	Fri Oct 15 12:29:39 2010 +0300
@@ -0,0 +1,73 @@
+/*
+* Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+package com.nokia.microedition.m2g;
+
+/**
+ * Class that wraps runnable in order to catch and forward
+ * exceptions that occured when executing in UI thread.
+ * This class is used only for running native methods in UI thread.
+ */
+abstract class M2GRunnableQt implements Runnable
+{
+    private Throwable e = null;
+
+    /**
+     * From Runnable interface
+     */
+    public void run()
+    {
+        try
+        {
+            doRun();
+        }
+        catch (Throwable t)
+        {
+            e = t;
+        }
+    }
+
+    /**
+     * Checks for possible exceptions and errors and throws them forward.
+     * Only unchecked exceptions and errors are thrown as only checked
+     * exception that m3gcore may throw comes from loader which is not
+     * executed in UI thread
+     *
+     * @throws RuntimeException
+     * @throws Error
+     */
+    public void checkAndThrow()
+    {
+        if (e == null)
+        {
+            return;
+        }
+        if (e instanceof RuntimeException)
+        {
+            throw(RuntimeException)e;
+        }
+        else if (e instanceof Error)
+        {
+            throw(Error)e;
+        }
+    }
+
+    /**
+     * Method to be implemented for the UI thead execution
+     */
+    abstract void doRun();
+}
\ No newline at end of file