javauis/m3g_qt/javasrc/javax/microedition/m3g/M3gRunnable.java
changeset 35 85266cc22c7f
equal deleted inserted replaced
26:dc7c549001d5 35:85266cc22c7f
       
     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 
       
    19 package javax.microedition.m3g;
       
    20 
       
    21 /**
       
    22  * Class that wraps runnable in order to catch and forward
       
    23  * exceptions that occured when executing in UI thread.
       
    24  * This class is used only for running native methods in UI thread.
       
    25  */
       
    26 abstract class M3gRunnable implements Runnable
       
    27 {
       
    28     private Throwable e = null;
       
    29 
       
    30     /**
       
    31      * From Runnable interface
       
    32      */
       
    33     public void run()
       
    34     {
       
    35         try
       
    36         {
       
    37             doRun();
       
    38         }
       
    39         catch (Throwable t)
       
    40         {
       
    41             e = t;
       
    42         }
       
    43     }
       
    44 
       
    45     /**
       
    46      * Checks for possible exceptions and errors and throws them forward.
       
    47      * Only unchecked exceptions and errors are thrown as only checked
       
    48      * exception that m3gcore may throw comes from loader which is not
       
    49      * executed in UI thread
       
    50      *
       
    51      * @throws RuntimeException
       
    52      * @throws Error
       
    53      */
       
    54     public void checkAndThrow()
       
    55     {
       
    56         if (e == null)
       
    57         {
       
    58             return;
       
    59         }
       
    60         if (e instanceof RuntimeException)
       
    61         {
       
    62             throw(RuntimeException)e;
       
    63         }
       
    64         else if (e instanceof Error)
       
    65         {
       
    66             throw(Error)e;
       
    67         }
       
    68     }
       
    69 
       
    70     /**
       
    71      * Method to be implemented for the UI thead execution
       
    72      */
       
    73     abstract void doRun();
       
    74 }