Tag: exception

Java Mail超时和connectiontimeout处理

我正在使用JavaMail向SMTP服务器发送电子邮件请求。 我想在我的代码中设置“mail.smtp.connectiontimeout”和“mail.smtp.timeout”属性。 从编程方面来说,我希望在Java中达到超时和/或connectiontimeout操作时捕获它们并相应地处理事情。 在这个意义上的处理,我需要在下次再次重试同一封电子邮件。 如何在Java / JavaMail中处理此问题? 是否可以捕获并处理此超时操作? 编辑 此外,假设我已完成对SMTP服务器的管理访问,是否可以自行模拟/重现此超时操作?

使用FileUtils.copyFile复制文件

我试图使用文件utils复制文件方法复制文件。 我正在遇到一些有时抛出exception的问题 java.io.IOException: Failed to copy full contents from ‘path.xml’ to localfile.xml 我在google搜索并在代码中看到当目标文件长度与目标文件长度不同时抛出此exception,exception仅发生一些时间 – 这可能是由于我尝试复制的文件是一致的更新所以我可能会在更新中捕获它(只是一个值更改的xml文件) 如果我将调用包装在if(target.canRead())但这似乎没什么区别。 有人可以帮忙吗? * 更新: *我无法锁定文件,因为它是通过第三方供应商写入的,这会导致各种问题。

如何模拟void方法抛出exception?

我有这样的结构: public class CacheWrapper { private Map innerMap; public CacheWrapper() { //initialize the innerMap with an instance for an in-memory cache //that works on external server //current implementation is not relevant for the problem innerMap = …; } public void putInSharedMemory(Object key, Object value) { innerMap.put(key, value); } public Object getFromSharedMemory(Object key) { return innerMap.get(key); […]

使用附件文件读取邮件时缺少启动边界exception

我不知道为什么当从邮件服务器读取带有附件文件的邮件时,我收到以下exception: Exception in thread “main” javax.mail.MessagingException: Missing start boundary at javax.mail.internet.MimeMultipart.parsebm<MimeMultipart.java:872) at javax.mail.internet.MimeMultipart.parse<MimeMultipart.java:493) at javax.mail.internet.MimeMultipart.getCount<MimeMultipart.java:240) at GetParts.handleMultipart(GetParts.java:57) at GetParts.main(GetParts.java:42) 我用来读取这些消息的文件是: import java.io.*; import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; public class GetParts { public static void main (String args[]) throws Exception { String host = args[0]; String username = args[1]; String password = args[2]; // Get […]

块捕获中的丢失exception

我运行这段代码: public class User { public static void main(String args[]) { int array[] = new int[10]; int i = 1; try { System.out.println(“try: ” + i++); System.out.println(array[10]); System.out.println(“try”); } catch (Exception e) { System.out.println(“catch: ” + i++); System.out.println(array[10]); System.out.println(“catch”); } finally { System.out.println(“finally: ” + i++); Object o = null; o.hashCode(); System.out.println(“finally”); } } } […]

无法复制:“比较方法违反了其总合同!”

我收到以下错误:“比较方法违反了其总合同!” 使用以下比较器时,我无法使用jUnit复制exception。 我想知道导致这个问题的原因以及如何复制它。 其他一些例子有相同的问题而不是如何复制它。 public class DtoComparator implements Comparator { @Override public int compare(Dto r1, Dto r2) { int value = 0; value = r1.getOrder() – r2.getOrder(); if (value == 0 && !isValueNull(r1.getDate(), r2.getDate())) value = r1.getDate().compareTo(r2.getDate()); return value; } private boolean isValueNull(Date date, Date date2) { return date == null || date2 == null; […]

如何使用java配置和没有Web.xml处理Spring MVC中的404页面未找到exception

我想在我的Spring MVC Web应用程序中处理404页面未找到exception,我正在使用SPRING 4.2.5.RELEASE ,我已经阅读了有关此主题的几个问题,但类似的问题是使用不同的spring java配置。 我有一个全局exception处理程序控制器类,它具有我的所有exception,这个类工作正常,但我无法处理404页面未找到exception。 这是我按照教程学习的方法 1)我创建了一个名为ResourceNotFoundException的类,它从RuntimeException扩展而来,我把这个注释放在了类定义@ResponseStatus(HttpStatus.NOT_FOUND) 像这样: @ResponseStatus(HttpStatus.NOT_FOUND) public class ResourceNotFoundException extends RuntimeException { } 2)我在exception的控制器类中创建了这个方法 @ExceptionHandler(ResourceNotFoundException.class) @ResponseStatus(HttpStatus.NOT_FOUND) public String handleResourceNotFoundException() { return “notFoundJSPPage”; } 但是,当我放置一个不存在的URL时,我收到此错误“找不到带HTTP的HTTP请求的映射” 我读过的问题说我需要启用Dispatcher的true选项,但由于我的配置与其他问题不同,我没有Web.xml所以我无法应用。 这是我的Config.java @EnableWebMvc @Configuration @ComponentScan({“config”, “controllers”}) public class ConfigMVC extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler(“/resources/**”).addResourceLocations(“/WEB-INF/resources/”); } @Bean public UrlBasedViewResolver setupViewResolver() { UrlBasedViewResolver […]

Spring XSD的访问错误

我正在尝试在我的工作中运行一名前雇员留下的系统,但我遇到了问题。 如果XSD通过远程访问运行: 它给出了一个未找到的exception: Failed to read schema document ‘http://www.springframework.org/schema/context/spring-context-3.0.xsd’, because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not . 如果XSD通过本地访问运行: 它给出了这个例外: C:\Users\claudiomazur>java -jar c:\temp\fin\c.jar 0 [AWT-EventQueue-0] INFO support.ClassPathXmlApplicationContext – Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@4fa52fdf: startup date [Thu Sep 06 11:22:59 BRT 2012]; root of […]

JVM如何知道在运行时捕获exception的位置?

根据我的理解, throw是一个灵长类似的jvm命令。 调用它时,JVM“检查当前调用堆栈是否可以捕获它”。 如果它不能,那么java只是简单地弹出调用栈,就像调用一个返回一样。 然后jvm“检查当前调用堆栈是否可以捕获它”等等递归。 我的问题:JVM在算法上如何知道调用堆栈中哪些地方可以捕获给定的exception? 每个调用堆栈条目中是否存储了元数据,将exception映射到代码块? 堆中是否有一个静态数据结构以某种方式跟踪它? 因为某处必须有数据跟踪。

无法在Google App引擎上部署应用程序:appengine-web.xml不包含元素

当我点击在netbeans中的谷歌应用引擎上部署应用程序时,这些是产生的错误消息。 我告诉你,最初,我输入的密码错误,应用程序无法部署。 但现在,当我点击部署应用程序时,它不会问我电子邮件或密码。 无论如何我如何解决这些错误? Reading application configuration data… Bad configuration: appengine-web.xml does not contain a element. See http://code.google.com/appengine/docs/java/config/appconfig.html#Using_Concurrent_Requests for more information. You probably want to enable concurrent requests. Please see the logs [C:\Users\user\AppData\Local\Temp\appcfg6534187344911851576.log] for further information. May 28, 2012 12:35:54 PM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml INFO: Successfully processed W:/UnderTest/NetbeansCurrent/Guestbook/build/web\WEB-INF/appengine-web.xml May 28, 2012 12:35:54 PM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml SEVERE: […]