exception-handling

Sonar complaining about logging and rethrowing the exception

浪尽此生 提交于 2020-06-17 09:31:11
问题 I have the following piece of code in my program and I am running SonarQube 5 for code quality check on it after integrating it with Maven. However, Sonar is complaining that I should Either log or rethrow this exception . What am I missing here? Am I not already logging the exception? private boolean authenticate(User user) { boolean validUser = false; int validUserCount = 0; try { DataSource dataSource = (DataSource) getServletContext().getAttribute("dataSource"); validUserCount = new

InputMismatchException when using Sacnner nextLine for String [duplicate]

别说谁变了你拦得住时间么 提交于 2020-06-13 05:55:11
问题 This question already has answers here : Scanner is skipping nextLine() after using next() or nextFoo()? (19 answers) Closed 3 years ago . This is my code import java.io.*; import java.util.*; class student { String name; int age; float cgpa; } public class getdata { public static void main(String args[]) throws IOException { Scanner in=new Scanner(System.in); int n; n=in.nextInt(); student[] s=new student[n]; for(int i=0;i<n;i++) { try { s[i]=new student(); s[i].name=in.nextLine(); in

Catching an InputMismatchException until it is correct [duplicate]

廉价感情. 提交于 2020-06-12 07:14:16
问题 This question already has answers here : How to handle infinite loop caused by invalid input (InputMismatchException) using Scanner (5 answers) How to use Scanner to accept only valid int as input (6 answers) Closed 2 years ago . I am trying add catch blocks to my program to handle input mismatch exceptions. I set up my first one to work inside of a do while loop, to give the user the opportunity to correct the issue. System.out.print("Enter Customer ID: "); int custID=0; do { try { custID =

Catching an InputMismatchException until it is correct [duplicate]

為{幸葍}努か 提交于 2020-06-12 07:10:48
问题 This question already has answers here : How to handle infinite loop caused by invalid input (InputMismatchException) using Scanner (5 answers) How to use Scanner to accept only valid int as input (6 answers) Closed 2 years ago . I am trying add catch blocks to my program to handle input mismatch exceptions. I set up my first one to work inside of a do while loop, to give the user the opportunity to correct the issue. System.out.print("Enter Customer ID: "); int custID=0; do { try { custID =

catch(…) is not catching an exception, my program is still crashing

廉价感情. 提交于 2020-06-10 02:51:30
问题 I'm having a problem with a tester that my application crashes in initialization. I added more logging and exception handling but it still crashes with the generic "this program has stopped working" message rather than triggering my error handling. Given my main() looks like this and has catch(...) under what circumstances would this not be triggered? try{ simed::CArmApp app(0, cmd); for(bool done = false;!done;) { done = !app.frame(); } } catch(const std::runtime_error &e){

How do I test for an exact Exception message, rather than a substring, with PHPUnit?

谁说我不能喝 提交于 2020-06-08 16:52:44
问题 According to the PHPUnit Documentation on @expectedExceptionMessage , the string must only be a substring of the actual Exception thrown. In one of my validation methods, an array item is pushed for each error that occurs, and the final Exception message is displayed by imploding the array of errors. class MyClass { public function validate($a, $b, $c, $d) { if($a < $b) $errors[] = "a < b."; if($b < $c) $errors[] = "b < c."; if($c < $d) $errors[] = "c < d."; if(count($errors) > 0) throw new

How do I test for an exact Exception message, rather than a substring, with PHPUnit?

谁说胖子不能爱 提交于 2020-06-08 16:51:42
问题 According to the PHPUnit Documentation on @expectedExceptionMessage , the string must only be a substring of the actual Exception thrown. In one of my validation methods, an array item is pushed for each error that occurs, and the final Exception message is displayed by imploding the array of errors. class MyClass { public function validate($a, $b, $c, $d) { if($a < $b) $errors[] = "a < b."; if($b < $c) $errors[] = "b < c."; if($c < $d) $errors[] = "c < d."; if(count($errors) > 0) throw new

Why/how is org.json.JSONException unchecked?

心已入冬 提交于 2020-05-31 08:51:51
问题 Reading How to identify checked and unchecked exceptions in java? makes me wonder: Why is org.json.JSONException unchecked according to maven and eclipse? (no compilation error when not handled) Both are extending java.lang.Exception according to the javadoc and the source code... org.JSON.JSONArray produces no error without try/catch: For comparison, here is a checked exception example: atg.taglib.json.util.JSONArray produces an error without try/catch: atg.taglib.json.util.JSONArray

Why/how is org.json.JSONException unchecked?

你。 提交于 2020-05-31 08:48:58
问题 Reading How to identify checked and unchecked exceptions in java? makes me wonder: Why is org.json.JSONException unchecked according to maven and eclipse? (no compilation error when not handled) Both are extending java.lang.Exception according to the javadoc and the source code... org.JSON.JSONArray produces no error without try/catch: For comparison, here is a checked exception example: atg.taglib.json.util.JSONArray produces an error without try/catch: atg.taglib.json.util.JSONArray

Check that an exception is correctly raised in Python 2.7?

独自空忆成欢 提交于 2020-05-30 02:17:29
问题 Does anyone know how to check that an exception is raised correctly? I need something that works in Python 2.7. The below 'assert' is not quite correct method to use from the Python unittest library: assert ( a_a0_getinst.add_port("iTCK", ISC.PortType_INPUT) ), "Can't add duplicate port" The error I get is: Traceback (most recent call last): File "test_010_module.py", line 157, in runTest a_a0_addinst = a_a0.add_instance( "A00", b_a0 ) File "/nfs/sc/disks/sc_dteg_2004/users/acheung1/dteg