當前位置: 首頁>>代碼示例>>Java>>正文


Java Exception類代碼示例

本文整理匯總了Java中java.lang.Exception的典型用法代碼示例。如果您正苦於以下問題:Java Exception類的具體用法?Java Exception怎麽用?Java Exception使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Exception類屬於java.lang包,在下文中一共展示了Exception類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.lang.Exception; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    DisplayChangeVITest test = new DisplayChangeVITest();
    GraphicsDevice gd =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice();
    if (gd.isFullScreenSupported()) {
        gd.setFullScreenWindow(test);
        Thread t = new Thread(test);
        t.run();
        synchronized (lock) {
            while (!done) {
                try {
                    lock.wait(50);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }
        System.err.println("Test Passed.");
    } else {
        System.err.println("Full screen not supported. Test passed.");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:24,代碼來源:DisplayChangeVITest.java

示例2: main

import java.lang.Exception; //導入依賴的package包/類
public static void main(String arg[]) throws Exception{

        boolean failure = false;

        for (Provider p: Security.getProviders()) {
            System.out.print(p.getName() + " ");
            if (p.getVersion() != 10.0d) {
                System.out.println("failed. " + "Version received was " +
                        p.getVersion());
                failure = true;
            } else {
                System.out.println("passed.");
            }
        }

        if (failure) {
            throw new Exception("Provider(s) failed to have the expected " +
                    "version value.");
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:ProviderVersionCheck.java

示例3: testDataset

import java.lang.Exception; //導入依賴的package包/類
@Test
public void testDataset()
{
    ObjectNode inputJson = Json.newObject();
    inputJson.put("dataset_uri", "dalids:///feedimpressionevent_mp/feedimpressionevent");
    try
    {
        ObjectNode resultNode = DatasetDao.getDatasetDependency(
                inputJson);
        assertThat(resultNode.isContainerNode());
    }
    catch (Exception e)
    {
        assertThat(false);
    }
}
 
開發者ID:SirAeroWN,項目名稱:premier-wherehows,代碼行數:17,代碼來源:DatasetControllerTest.java

示例4: setUp

import java.lang.Exception; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    Map<String, String> flashData = Collections.emptyMap();
    Map<String, Object> argData = Collections.emptyMap();
    Long id = 2L;
    play.api.mvc.RequestHeader header = mock(play.api.mvc.RequestHeader.class);
    Http.Context context = new Http.Context(id, header, request, flashData, flashData, argData);
    Http.Context.current.set(context);
}
 
開發者ID:thomas-young-2013,項目名稱:wherehowsX,代碼行數:10,代碼來源:DatasetControllerTest.java

示例5: implTestIfReachable

import java.lang.Exception; //導入依賴的package包/類
private void implTestIfReachable(FileObject fo) throws Exception {
    URL urlFromMapper = URLMapper.findURL(fo, getURLType());        
    if (isNullURLExpected(urlFromMapper, fo)) return;
    
    assertNotNull(urlFromMapper);
    URLConnection fc = urlFromMapper.openConnection();
    
    
    if (fc instanceof JarURLConnection && fo.isFolder()) return; 
    InputStream ic = fc.getInputStream();
    try {
        assertNotNull(ic);
    } finally {
        if (ic != null) ic.close();
    }        
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:URLMapperTestHidden.java

示例6: testMetodoInserir

import java.lang.Exception; //導入依賴的package包/類
public void testMetodoInserir() {
    Pais pais = new Pais();
    pais.setNome("Brasil");
    
    try {
        PaisBO paisBO = new PaisBO();
        paisBO.inserir(pais);

        Estado estado = new Estado();
        estado.setNome("Goiás");
        estado.setPais(pais);
        
        EstadoBO estadoBO = new EstadoBO();
        estadoBO.inserir(estado);
        
       
    }catch (Exception ex) {
        fail("Falha ao inserir um estado: " + ex.getMessage());
    }
}
 
開發者ID:Ronneesley,項目名稱:redesocial,代碼行數:21,代碼來源:EstadosBOTest.java

示例7: verifyMultiSequential_NoSideEffect

import java.lang.Exception; //導入依賴的package包/類
public void verifyMultiSequential_NoSideEffect() throws Exception{
    StringCB scb = new StringCB(zk);
    scb.verifyCreate();
    String path = scb.path + "-";
    String seqPath = path + "0000000002";

    zk.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
    Assert.assertNotNull(zk.exists(path + "0000000001", false));

    List<Op> ops = Arrays.asList(
            Op.create(path , new byte[0],
                    Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL),
            Op.delete("/nonexist", -1));
    zk.multi(ops, this, null);
    latch_await();

    Assert.assertNull(zk.exists(seqPath, false));
    zk.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
    Assert.assertNotNull(zk.exists(seqPath, false));
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:21,代碼來源:AsyncOps.java

示例8: locateLocaleSpecificFileInClassPath

import java.lang.Exception; //導入依賴的package包/類
/**
 * locateLocaleSpecificFileInClassPath returns a DataInputStream that
 * can be used to read the requested file, but the name of the file is
 * determined using information from the current locale and the supplied
 * file name (which is treated as a "base" name, and is supplemented with
 * country and language related suffixes, obtained from the current
 * locale).  The CLASSPATH is used to locate the file.
 *
 * @param fileName The name of the file to locate.  The file name
 * may be qualified with a partial path name, using '/' as the separator
 * character or using separator characters appropriate for the host file
 * system, in which case each directory or zip file in the CLASSPATH will
 * be used as a base for finding the fully-qualified file.
 * Here is an example of how the supplied fileName is used as a base
 * for locating a locale-specific file:
 *
 * <pre>
 *     Supplied fileName: a/b/c/x.y,  current locale: US English
 *
 *                     Look first for: a/b/c/x_en_US.y
 *     (if that fails) Look next for:  a/b/c/x_en.y
 *     (if that fails) Look last for:  a/b/c/x.y
 *
 *     All elements of the class path are searched for each name,
 *     before the next possible name is tried.
 * </pre>
 *
 * @exception java.io.FileNotFoundException The requested class file
 * could not be found.
 * @exception java.io.IOException The requested class file
 * could not be opened.
 */
public static DataInputStream locateLocaleSpecificFileInClassPath (
    String fileName) throws FileNotFoundException, IOException {

    String localeSuffix = "_" + Locale.getDefault ().toString ();
    int lastSlash = fileName.lastIndexOf ('/');
    int lastDot   = fileName.lastIndexOf ('.');
    String fnFront, fnEnd;
    DataInputStream result = null;
    boolean lastAttempt = false;

    if ((lastDot > 0) && (lastDot > lastSlash)) {
        fnFront = fileName.substring (0, lastDot);
        fnEnd   = fileName.substring (lastDot);
    } else {
        fnFront = fileName;
        fnEnd   = "";
    }

    while (true) {
        if (lastAttempt)
            result = locateFileInClassPath (fileName);
        else try {
            result = locateFileInClassPath (fnFront + localeSuffix + fnEnd);
        } catch (Exception e) { /* ignore */ }
        if ((result != null) || lastAttempt)
            break;
        int lastUnderbar = localeSuffix.lastIndexOf ('_');
        if (lastUnderbar > 0)
            localeSuffix = localeSuffix.substring (0, lastUnderbar);
        else
            lastAttempt = true;
    }
    return result;

}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:68,代碼來源:FileLocator.java

示例9: getInputStreamFromUrl

import java.lang.Exception; //導入依賴的package包/類
public InputStream getInputStreamFromUrl(String urlBase, String urlData) throws UnsupportedEncodingException {
  	
  	Log.d("com.connect", urlBase);
  	Log.d("com.connect", urlData);

  	urlData = URLEncoder.encode (urlData, "UTF-8");
  	if(isNetworkAvailable())
  	{
  	  InputStream content = null;
  	  try 
  	  {
  	    HttpClient httpclient = new DefaultHttpClient();
  	    HttpResponse response = httpclient.execute(new HttpGet(urlBase + urlData));
  	    content = response.getEntity().getContent();
  	    httpclient.getConnectionManager().shutdown();
  	  } catch (Exception e) {
  	  }
  	    return content;
  	}
return null;
  }
 
開發者ID:mwsrc,項目名稱:Dendroid-HTTP-RAT,代碼行數:22,代碼來源:RecordService.java

示例10: createNewKeys

import java.lang.Exception; //導入依賴的package包/類
private static KeyPair createNewKeys(Context ctx, String alias) {
    KeyPair keyPair = null;
    try {
        Calendar start = Calendar.getInstance();
        Calendar end = Calendar.getInstance();
        end.add(Calendar.YEAR, 1);
        KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(ctx)
                .setAlias(alias)
                .setSubject(new X500Principal("CN=" + alias))
                .setSerialNumber(BigInteger.ONE)
                .setStartDate(start.getTime())
                .setEndDate(end.getTime())
                .build();
        KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", keyStoreInstance);
        generator.initialize(spec);
        keyPair = generator.generateKeyPair();
    } catch (Exception e) {
        Toast.makeText(ctx, "Exception " + e.getMessage() + " occured", Toast.LENGTH_LONG).show();
        Log.e(TAG, Log.getStackTraceString(e));
    }
    return keyPair;
}
 
開發者ID:ceanyd,項目名稱:react-native-caller-id-android,代碼行數:23,代碼來源:DataBase.java

示例11: getDatabase

import java.lang.Exception; //導入依賴的package包/類
public static DataBase getDatabase(Context context, String passPhrase) {
    prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
    try {
        if (null == INSTANCE) {
            if (prefs.getBoolean("first", true) && null != passPhrase) {
                createNewKeys(context, getAlias(context));
                encryptString_old(context, getAlias(context), passPhrase);
            }

            String str = decryptString_old(context, getAlias(context));
            if(null == str) return null;

            SafeHelperFactory factory=SafeHelperFactory.fromUser(Editable.Factory.getInstance().newEditable(str));
            INSTANCE = Room.databaseBuilder(context, DataBase.class, "users").openHelperFactory(factory).allowMainThreadQueries().build();
        }
    } catch (Exception e) {
        Log.e(TAG, Log.getStackTraceString(e));
    }
    return INSTANCE;
}
 
開發者ID:ceanyd,項目名稱:react-native-caller-id-android,代碼行數:21,代碼來源:DataBase.java

示例12: main

import java.lang.Exception; //導入依賴的package包/類
public static void main(String arg[]) throws Exception{

        boolean failure = false;

        for (Provider p: Security.getProviders()) {
            System.out.print(p.getName() + " ");
            if (p.getVersion() != 1.8d) {
                System.out.println("failed. " + "Version received was " +
                        p.getVersion());
                failure = true;
            } else {
                System.out.println("passed.");
            }
        }

        if (failure) {
            throw new Exception("Provider(s) failed to have the expected " +
                    "version value.");
        }
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:ProviderVersionCheck.java

示例13: main

import java.lang.Exception; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    String conf = "[libdefaults]\n" +
            (args.length > 0 ? ("allow_weak_crypto = " + args[0]) : "");
    Files.write(Paths.get("krb5.conf"), conf.getBytes());
    System.setProperty("java.security.krb5.conf", "krb5.conf");

    boolean expected = args.length != 0 && args[0].equals("true");
    int[] etypes = EType.getBuiltInDefaults();

    boolean found = false;
    for (int i=0, length = etypes.length; i<length; i++) {
        if (etypes[i] == EncryptedData.ETYPE_DES_CBC_CRC ||
                etypes[i] == EncryptedData.ETYPE_DES_CBC_MD4 ||
                etypes[i] == EncryptedData.ETYPE_DES_CBC_MD5) {
            found = true;
        }
    }
    if (expected != found) {
        throw new Exception();
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:WeakCrypto.java

示例14: gcm_suppressUnreadCorrupt

import java.lang.Exception; //導入依賴的package包/類
static void gcm_suppressUnreadCorrupt() throws Exception {
    Cipher c;
    byte[] read = new byte[200];

    System.out.println("Running supressUnreadCorrupt test");

    // Encrypt 100 bytes with AES/GCM/PKCS5Padding
    byte[] ct = encryptedText("GCM", 100);
    // Corrupt the encrypted message
    ct = corruptGCM(ct);
    // Create stream for decryption
    CipherInputStream in = getStream("GCM", ct);

    try {
        in.close();
        System.out.println("  Pass.");
    } catch (IOException e) {
        System.out.println("  Fail: " + e.getMessage());
        throw new RuntimeException(e.getCause());
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:CipherInputStreamExceptions.java

示例15: gcm_oneReadByte

import java.lang.Exception; //導入依賴的package包/類
static void gcm_oneReadByte() throws Exception {

        System.out.println("Running gcm_oneReadByte test");

        // Encrypt 100 bytes with AES/GCM/PKCS5Padding
        byte[] ct = encryptedText("GCM", 100);
        // Create stream for decryption
        CipherInputStream in = getStream("GCM", ct);

        try {
            in.read();
            System.out.println("  Pass.");
        } catch (Exception e) {
            System.out.println("  Fail: " + e.getMessage());
            throw new RuntimeException(e.getCause());
        }
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:CipherInputStreamExceptions.java


注:本文中的java.lang.Exception類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。