About 14,100 results
Open links in new tab
  1. Exception with try-catch and loop in Java - Stack Overflow

    Jun 13, 2011 · The main difference is that in the first snippet of code, even if there is an exception thrown from the try block and it is caught execution of the for loop continues. In the second snippet if an exception is thrown then the for loop is exited. This is because the whole loop is within the try block.

  2. java - A try-catch method in while loop? - Stack Overflow

    Mar 20, 2012 · I have this code, and I want to put the try-catch inside a while loop. The logic would be, "while there is an input error, the program would keep on asking for a correct input". How will I do that?

  3. java - while loop with exception handling - Stack Overflow

    do { try { Blob b = new Blob(id); break; } catch (Exception e) { System.out.println(e); } System.out.println("Enter a different ID: "); id = scan.nextInt(); } while(true); So each time the loop would reach the end of its body, it would break out of the loop.

  4. Mastering Exception Handling in Java: Effective Techniques within While

    This article delves into the nuances of implementing exception handling within while loops in Java, a common scenario in many applications. Exception handling in Java is managed using try-catch blocks, which allow developers to gracefully manage …

  5. Java Exceptions - Try...Catch - W3Schools

    If an error occurs, we can use try...catch to catch the error and execute some code to handle it: Example public class Main { public static void main(String[ ] args) { try { int[] myNumbers = {1, 2, 3}; System.out.println(myNumbers[10]); } catch (Exception e) { …

  6. Java Try Catch Block - GeeksforGeeks

    Jan 2, 2025 · try-catch block in Java is a mechanism to handle exceptions. This ensures that the application continues to run even if an error occurs. The code inside the try block is executed, and if any exception occurs, it is then caught by the catch block.

  7. Java Exception Handling - GeeksforGeeks

    Mar 25, 2025 · Exception handling in Java allows developers to manage runtime errors effectively by using mechanisms like try-catch block, finally block, throwing Exceptions, Custom Exception handling, etc.

  8. How to Handle Exceptions in Java and Continue Processing

    Use try-catch blocks around code that may throw exceptions to handle them gracefully. Implement multiple catch blocks for specific exception types, followed by a general catch for all other exceptions. Utilize the finally block to execute any cleanup code that must run whether an exception occurred or not.

  9. Exception Handling with Try Catch in Java | Career Karma

    Mar 18, 2020 · This tutorial will discuss the basics of exception handling, how to use the try...catch block to handle exceptions, and how to use the finally statement with try...catch. We’ll also walk through a few examples of the try...catch block in action.

  10. Mastering Exception Handling and Try/Catch Blocks in Java

    Jan 27, 2025 · The primary mechanism for handling exceptions in Java is the try/catch block. It allows you to catch thrown exception objects and handle them gracefully. Here is the general syntax: try { // Code that could throw an exception } catch (ExceptionType e) { // Handle exception }

Refresh