本文整理汇总了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.");
}
}
示例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.");
}
}
示例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);
}
}
示例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);
}
示例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();
}
}
示例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());
}
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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.");
}
}
示例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();
}
}
示例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());
}
}
示例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());
}
}