这是我的代码
#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
char *str = "First string";
char *str2 = "Second string";
strcpy(str, str2);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它编译得很好没有任何警告或错误,但当我运行应用程序时,我得到了该错误
Bus error: 10
Run Code Online (Sandbox Code Playgroud)
我想念的是什么?
以下是我的声纳属性片段:
sonarqube {
properties{
property "sonar.junit.reportPaths", "build/test-results/testDebugUnitTest/*.xml"
property("sonar.coverage.jacoco.xmlReportPaths", "build/reports/jacocoTestReport.xml"
}
}
Run Code Online (Sandbox Code Playgroud)
Jacoco 配置和属性工作正常,我如何确认这一点?我创建了一个 java 类并为其编写了一个单元测试,sonarqube 识别了这一点并将其记录为代码覆盖率的一部分,而它基本上忽略了所有 Kotlin 文件测试。我继续将 kotlin 文件更改为 java,并为其编写了一个 UnitTest,是的,它被识别并添加为代码覆盖率的一部分,再次,kotlin 文件测试被忽略。
顺便说一句,下面是我的 Jacoco.gradle:
apply plugin: 'jacoco'
ext {
coverageExclusions = [
'**/*Activity*.*',
'**/*Fragment*.*',
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
]
}
jacoco {
toolVersion = '0.8.6'
reportsDir = file("$buildDir/reports")
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
tasks.withType(Test) {
finalizedBy jacocoTestReport // report is always generated after tests run
}
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) {
group = "Reporting" …Run Code Online (Sandbox Code Playgroud) 捕获像下面的选项1这样的特定异常非常普遍,也是捕获异常的最简便方法。为什么很少考虑选项2的原因是因为它变得难以理解,这就是我对“为什么”的了解。我的问题是,像选项2(常规异常)这样的深度风险捕获异常是什么?我知道应该有,我想知道。请原谅我的语法。
try{
TextIO.putf(s);
FileOutputStream mFileOutputStream = new FileOutputStream("/content/doc/test.pdf", true);
}catch (FileNotFoundException notfEx){
//Do something
}catch (NullPointerException nullEx){
//Do something
}catch(IllegalArgumentException illEx){
//Do something
}
Run Code Online (Sandbox Code Playgroud)
try{
TextIO.putf(s);
FileOutputStream mFileOutputStream = new FileOutputStream("/content/doc/test.pdf", true);
}catch (Exception ex){
if(ex.getClass() == java.io.FileNotFoundException.class) {
//Do something
}else if(ex.getClass() == java.lang.IllegalArgumentException.class){
//Do something
}else if(ex.getClass() == java.lang.NullPointerException.class){
//Do something
}
}
}
Run Code Online (Sandbox Code Playgroud)