当前位置: 首页>>代码示例>>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;未经允许,请勿转载。