草庐IT

EXCEPTION

全部标签

java - 异常重写方法

下面是书中的引述:TheoverridingmethodmustNOTthrowcheckedexceptionsthatareneworbroaderthanthosedeclaredbytheoverriddenmethod.Forexample,amethodthatdeclaresaFileNotFoundExceptioncannotbeoverriddenbyamethodthatdeclaresaSQLException,Exception,oranyothernon-runtimeexceptionunlessit'sasubclassofFileNotFoundExc

java - 在测试中模拟 CompletionException

我有一个HttpClient类,它有一个返回CompletableFuture的函数:publicclassHttpClient{publicstaticCompletableFuturegetSize(){CompletableFuturefuture=ClientHelper.getResults().thenApply((searchResults)->{returnsearchResults.size();});returnfuture;}}然后另一个函数调用这个函数:publicclassCaller{publicstaticvoidcaller()throwsExcepti

java.lang.ClassFormat错误: Extra bytes at end of class file

当我尝试运行这个程序时,我遇到了一个奇怪的错误。该类可以很好地编译成多个.class文件,我上周(在编辑它之前)编译它就好了。但是现在,我看到了:Exceptioninthread"main"java.lang.ClassFormatError:Extrabytesattheendofclassfileblah/hooplah/fubar/nonsense/IndexId$Transaction根据我的了解,Java6build1.5可以修复它,因为它允许在类文件末尾添加额外的字节(我认为),但我更愿意使用build1.6。我在Windows上编辑,然后通过FTP将.java文件传输到

java - 使用 JUnit 4 的预期异常机制导致意外行为的原因?

我正在尝试测试特定方法是否会从方法中抛出预期的异常。根据JUnit4文档和thisanswer我把测试写成:@Test(expected=CannotUndoException.class)publicvoidtestUndoThrowsCannotUndoException(){//codetoinitialise'command'command.undo();}但是,此代码未通过JUnit测试,将抛出的(和预期的)异常报告为错误。我正在测试的方法在主体中只有这个:publicvoidundo(){thrownewCannotUndoException();}此外,以下测试通过:pu

java - GWT 服务异常日志记录的最佳实践

我决定将日志系统添加到我的gwt服务层。首先,我想记录从该层抛出的所有异常。我有一个类似于Spring的ServletDispatcher的对象,它调用其他服务。我以为我可以在那里添加日志记录,但我意识到GWT服务将已检查的异常包装在ServletResponse中,并将未检查的异常包装到UnexpectedException中。任何人都可以分享他在这个问题上的经验吗?记录所有GWT服务的已检查和未检查异常的最佳方法是什么。我找到了建议扩展RemoteServiceServlet并覆盖默认异常流的解决方案。但我觉得这个解决方案太费时了。有人知道更简单的变体吗?

java.rmi.ServerException : RemoteException occurred in server thread (ClassNotFoundException) 异常

以下方法:privatevoidstartServer(){//snippetthatstartstheserveronthelocalmachinetry{RemoteMethodImplimpl=newRemoteMethodImpl();Naming.rebind("Illusive-Server",impl);}catch(Exceptionexc){JOptionPane.showMessageDialog(this,"Problemstartingtheserver","Error",JOptionPane.ERROR_MESSAGE);System.out.println

Java 无效命令行参数异常

JavaAPI中是否有针对无效命令行参数的适当异常类,还是我必须创建自己的异常类?我试过搜索,但在API中找不到。这是为了作业,所以我不能使用第三方库进行命令行解析。 最佳答案 大多数时候,当接收到的参数无效时,抛出一个IllegalArgumentException是一个常见的习惯用法。.publicclassIllegalArgumentExceptionextendsRuntimeExceptionThrowntoindicatethatamethodhasbeenpassedanillegalorinappropriatea

java - 严重 : Exception starting filter CORS

我在tomcat上部署了RESTfulWeb服务'该Web服务在同一域场景的客户端/服务器中工作正常'但我需要使Web服务可从跨域使用'为此我使用了CORS过滤器.我在myProjects/lib和tomcat/lib中都包含了过滤器的jars',还在我的Web服务项目的web.xml文件中包含了以下内容'CORScom.thetransactioncompany.cors.CORSFiltercors.supportedHeadersAccept,Origin,X-Requested-With,Content-Type,Last-ModifiedCORS/*但是,当我尝试启动Web服

java - SpringBoot 不处理 org.hibernate.exception.ConstraintViolationException

我已经在我的实体类中定义了一个验证电子邮件的模式。在我的验证异常处理程序类中,我添加了ConstraintViolationException的处理程序。我的应用程序使用SpringBoot1.4.5。配置文件.java@Entity@EntityListeners(AuditingEntityListener.class)@Table(name="profile")publicclassProfileextendsAuditableEntity{privatestaticfinallongserialVersionUID=8744243251433626827L;@Column(na

java - 使用 DecimalFormat 进行格式化会引发异常 - "Cannot format given Object as a Number"

这可能看起来像一个重复的问题,但我尝试了以下所有链接,但无法得到正确的答案。CannotformatgivenObjectasaNumberComboBoxIllegalArgumentException但我不明白哪里出了问题。这是我的代码DecimalFormattwoDForm=newDecimalFormat("#.##");doubleexternalmark=1.86;doubleinternalmark=4.0;System.out.println(String.valueOf((externalmark*3+internalmark*1)/4));Stringval=St