小编use*_*339的帖子

以编程方式区分异常

异常的类型通常足以正确处理它(例如,您尝试打开文件并获取a FileNotFoundException).但是,在某些情况下,您可能会捕获同一类型的多个异常.例如,一个IllegalArgumentException可能由多个参数引起的.这IllegalArgumentException不会向Throwable接口添加任何其他方法(或公共字段)(根据在线javadoc),这意味着您可以依赖的唯一信息是嵌套异常(可能存在也可能不存在)和消息(是供人食用的).

我不喜欢扩展IllegalArgumentException为其添加结构化信息的想法,因为其他人必须学习新课程.而且我不喜欢乱扔乱画项目的想法非常具体的异常类.使用消息字段也是一个坏主意,因为它不适用于编程访问.

我认为IllegalArgumentException应该包括诸如类函数和有争议的参数之类的细节.通常,自定义异常应该提供额外的细节(除了它们的类型之外),以便进行更细粒度的异常处理.

什么通常被认为是设计异常类和处理相同类型的异常的最佳实践?

java exception-handling

2
推荐指数
1
解决办法
995
查看次数

删除尾随数字

当我在代码下面运行时,为什么我会得到这么多数字?

BigDecimal lat =  new BigDecimal(0.0077);

System.out.println(lat);
Run Code Online (Sandbox Code Playgroud)

输出>> 0.00770000000000000024702462297909733024425804615020751953125

我想准确打印我输入的内容.我怎样才能做到这一点?

java bigdecimal

2
推荐指数
1
解决办法
183
查看次数

FileWriter写入文件

我如何使用FileWriter实际写入文件,然后在记事本上打开它,看看我写了什么?这是我到目前为止所尝试的:

package Experimental;

import java.io.*;

public class IO {

    public static void main (String args[]) {

       File f = new File("testFile.txt");

       //Outputting into a file
       try {

          PrintWriter filePrint = new PrintWriter(
             new BufferedWriter(new FileWriter(f,true))
          );
          filePrint.println("testing, testing, printing into a file (apparently)");
       } catch (IOException e) {
          System.out.println(e.getMessage());
       }
   }
}
Run Code Online (Sandbox Code Playgroud)

java filewriter java-io

2
推荐指数
1
解决办法
139
查看次数

从 drools 会话中删除对象并在 spring 中重用相同的会话

我在服务类中使用自动连接的 StatefulKnowledgeSession。

@Service("vbOrderService")
public class VbOrderService {
    
    @Autowired
    private VbOrderDao vbOrderDao ;
    
    @Autowired
    StatefulKnowledgeSession vbDiscSession;
    
    public CpSellerDetails getStep1Data(Integer grpSellerId,Integer catalogueId) throws DataNotFoundException{
        return vbOrderDao.getStep1Data(grpSellerId,null,catalogueId);
    }
    /*public CpSellerDetails getStep1Data(Integer cp_id,Integer orderno) throws DataNotFoundException{
        return vbOrderDao.getStep1Data(cp_id,orderno);
    }*/
    public void getStep2Data(Integer cp_id,VbCpInfoBean info) throws DataNotFoundException{
        vbOrderDao.getStep2Data(cp_id,info);
    }
    public Integer updateStep2Data(VbCpInfoBean info,Integer cp_id) throws UpdateFailedException{
        return vbOrderDao.updateStep2Data(info,cp_id);
    }
    
    public void getOrderStep3(CpSellerDetails sellerDetails) throws DataNotFoundException {
         vbOrderDao.getOrderStep3(sellerDetails);
          fireRules(sellerDetails);
    }
    public void orderStep4(LoginBean user,CpSellerDetails sellerDetails) throws UpdateFailedException {
         vbOrderDao.orderStep4(user,sellerDetails);
        // fireRules(sellerDetails);
    }
    public CpSellerDetails getOrderDetailsForPdfGeneration(String orderno, …
Run Code Online (Sandbox Code Playgroud)

spring drools

2
推荐指数
1
解决办法
5086
查看次数

java.lang.NoClassDefFoundError:org/springframework/context/ApplicationContext maven

我是春天和maven的新手.我有一个使用Spring的简单hello world项目.项目构建成功但我在运行时遇到以下错误:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
Run Code Online (Sandbox Code Playgroud)

这是主要的应用程序:App.java

package com.test.SpringMaven2;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;



/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
        System.out.println( "Hello World!" );
        ApplicationContext context = new AnnotationConfigApplicationContext(HelloWorldConfig.class);

        HelloWorld hello = (HelloWorld) context.getBean("helloWorld"); 
        hello.setName("Adnan");
        hello.getName();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是HelloWorld bean

package com.test.SpringMaven2;

public class HelloWorld{


    private String name; 

    public void …
Run Code Online (Sandbox Code Playgroud)

java spring maven applicationcontext

2
推荐指数
1
解决办法
2万
查看次数

DataInputStream 和 OutputStream 写入/读取长度的字符串

如何读取Stringwith DataInputStream,与此代码一起存储:

DataOutputStream dataOut = new DataOutputStream (out); // Some other stream
String title = processed.getTitle();
dataOut.writeInt(title.length());
dataOut.writeBytes(title);
Run Code Online (Sandbox Code Playgroud)

java io java-io

1
推荐指数
1
解决办法
6740
查看次数

我是否需要开发者令牌才能从 Adwords 获取数据

我是否需要开发者令牌才能从 Adwords获取数据?

我只想获取一些数据,而不是创建/编辑/修改某些内容。

我的计划是让我的客户通过 oauth 进行身份验证,然后根据来自 adwords 的数据绘制一些图表。

在我看来,我必须获得开发人员密钥才能获取该数据(来源)。

这是正确的还是有其他方法可以从 AdWords 帐户中获取数据?

c# java google-api google-ads-api

1
推荐指数
1
解决办法
1139
查看次数

为什么我不能在linux中的代码块中使用"auto"

这是我第一次auto在c ++中使用,我在linux上工作,但我发现它根本不起作用.我想知道发生了什么.这是我的代码:

    //<STL container.cpp>
    //date: 2014.3.9 10:45
    #include<iostream>
    //#include<iterator>
    #include<vector>
    using namespace std;
    int main()
    {
        double a= 10.0;
        auto b=a;
        cout<<b;
        //for(auto it = mydata.begin();;it!=mydata.end();it++)
           // cout<<" "<<*it;
        cout<<endl;
        return 0;
    }
Run Code Online (Sandbox Code Playgroud)

和代码块告诉我:

error:'b' does not name a type
error:'b' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)

我想知道codeblocks是不引用auto还是linux不引用.

c++ linux codeblocks auto

0
推荐指数
1
解决办法
3306
查看次数

为什么这段代码不起作用?C++

我正在学习cpp并需要一些帮助.我的代码无效,它停止了add->value = value.

typedef struct node node;
struct node{
    int value;
    struct node *next;  
};

node *top; 

int insert(int value){
    struct node *add;
    cout<< "here it stops";
    add->value = value;
    add->next = NULL;

    if(top == NULL ){
        top == add;
    }else{
        add->next = top;
        top =  add;
    }  
}
Run Code Online (Sandbox Code Playgroud)

c++ pointers memory-management

-3
推荐指数
1
解决办法
161
查看次数