草庐IT

set_exception

全部标签

java - 为什么要设置 "sun.awt.exception.handler"属性呢?

下面是一些代码,用于捕获在事件调度线程上抛出的异常:packagecom.ndh.swingjunk;importjava.awt.EventQueue;importjavax.swing.JFrame;publicclassEntryPoint{publicstaticvoidmain(String[]args){Thread.setDefaultUncaughtExceptionHandler(newMyExceptionHandler());//System.setProperty("sun.awt.exception.handler",MyExceptionHandler.cl

Java 8 map : filter value and throw exception if match found

我正在尝试在Map中查找匹配值,如果找到,我需要抛出IllegalArgumentException。我的代码如下:finalStringstringToBeMatched="someRandomString";map.values().stream().filter(a->stringToBeMatched==a.getField()).findAny().ifPresent(a->thrownewIllegalArgumentException());我在token“throw”上遇到语法错误。我不确定我哪里出错了。 最佳答案

java - token 端点 : Handling Null Pointer Exception

我尝试通过curl执行此命令从我的oauth2服务器请求代码curl-XPOST-k-vuclientapp:123456http://localhost:8080/oauth/token-H"Accept:application/json"-d"grant_type=authorization_code&scope=read%20write&client_secret=123456&client_id=clientapp&code=appcode&redirect_uri=localhost:3000"响应是*Addinghandle:conn:0x608860*Addinghand

java - 为什么java ArrayIndexOutOfBound Exception Extends IndexOutofBound Exception not Throwable?

我对ExceptionwithInheritance有疑问。为什么公共(public)类ArrayIndexOutOfBoundsException扩展IndexOutOfBoundsException然后公共(public)类IndexOutOfBoundsException扩展了RuntimeException然后公共(public)类RuntimeException扩展异常为什么不公共(public)类ArrayIndexOutOfBoundsException扩展异常为什么要保持这种层次结构。任何指导都会有帮助吗? 最佳答案

java - 带有 Chrome 驱动程序的 Selenium 网格(WebDriverException : The path to the driver executable must be set by the webdriver. chrome.driver 系统属性)

我正在尝试让我的SeleniumGrid在Chrome驱动程序上运行。一开始我启动了hub和node:java-jarselenium-server-standalone-2.45.0.jar-rolehubjava-jarselenium-server-standalone-2.45.0.jar-rolenode-hubhttp://localhost:4444/grid/register比我启动我的测试:publicclassChromeDriverTest{privateWebDriverdriver=null;StringBaseURL,NodeURL;@Beforepubli

java - 好奇 : Why is the "throws <SomeSpecific>Exception" syntax required in Java alone?

我们都知道它是必需的。但是为什么仅在Java中需要它,而其他具有异常处理能力的类似语言不需要我们编写“throwsException”?有没有人知道在设计Java语言时发生了什么以及为什么要这样做?只是好奇。附言这可能不是一个实际或真正必要的问题-它可能对我正在进行的项目无论如何都没有帮助。但是某些语言特性激起了我的好奇心:D编辑看来我的问题很含糊!我想我错误地表达了这个问题。在处理Java代码的编程过程中,我们需要在某些时候使用“throwsException”类语法。但是在C#或C++甚至VB.Net和PHP中从来不需要类似的东西。那么为什么只有Java坚持这样做呢?

java - Spring 框架 : instantiation exception

我是SpringFramework的新手,所以我决定买一本书(“Springinaction”第3版)。目前我在第一章,涵盖基础知识-依赖注入(inject)(DI)和面向方面的编程(AOP)。我设法运行了显示DI的代码。1#knight实现的接口(interface)packagecom.springinaction.knights;publicinterfaceKnight{voidembarkOnQuest()throwsQuestException;}1#骑士等级packagecom.springinaction.knights;publicclassBraveKnightim

java - Windows下Maven安装 : "JAVA_HOME is set to an invalid directory"

这个问题在这里已经有了答案:UnabletoinstallMavenonWindows:"JAVA_HOMEissettoaninvaliddirectory"(16个答案)关闭8年前。我是Maven的新手,我已经下载了3.0.5版本。我收到以下错误:JAVA_HOMEissettoaninvaliddirectory.pleasesetthejava_homevariableinyourenvironmentvariabletomatchthelocationofyourjavainstallation不过,当我在命令提示符下键入javac或echo%M2_HOME%时,我没有看到任

java - 总是使用 get 和 set 方法来访问类自己的成员字段是否属于反模式?

这个问题在这里已经有了答案:Usinggetterswithinclassmethods(6个答案)关闭9年前。在Java类中,使用getter和setter访问成员字段被认为是好习惯还是坏习惯?例如哪个更好:publicOrder{privateAgreementagreement;publicAgreementgetAgreement(){returnagreement;}publicvoidprocess(){//shouldIuse:getAgreement().doSomething();//Or:agreement.doSomething();}}一般来说,由于KISS原则

java - String get/set 是线程安全的吗?

假设我有以下内容,publicclassFoo{privateStringbar;publicStringgetBar(){returnbar;}publicvoidsetBar(Stringbar){this.bar=bar;}}由于String类的不可变特性,这些方法是否自动线程安全,或者是否需要某种锁定机制? 最佳答案 不,这不是线程安全的。Foo是可变的,所以如果你想确保不同的线程看到相同的值bar–即一致性–或者:制作barvolatile,或制作方法synchronized,或使用AtomicReference.bar的