try-catch

What is the scope of a variable defined inside java try block? Why it is not accessible outside of the try block?

蓝咒 提交于 2019-12-12 02:44:52
问题 In the below java program even though the member "x" is defined outside the try block, it is accessible inside the try block. In case of "y", it is defined inside try block. But it is not accessible outside the try block. Why it is so? package com.shan.interfaceabstractdemo; public class ExceptionDemo { public static void main(String[] args) { int x = 10; try { System.out.println("The value of x is:" + x); int y = 20; } catch (Exception e) { System.out.println(e); } System.out.println("The

Java accepting only numbers from user with Scanner

﹥>﹥吖頭↗ 提交于 2019-12-12 02:29:08
问题 I am trying to understand how to only accept numbers from the user, and I have attempted to do so using try catch blocks, but I would still get errors with it. Scanner scan = new Scanner(System.in); boolean bidding; int startbid; int bid; bidding = true; System.out.println("Alright folks, who wants this unit?" + "\nHow much. How much. How much money where?" ); startbid = scan.nextInt(); try{ while(bidding){ System.out.println("$" + startbid + "! Whose going to bid higher?"); startbid =+ scan

Java Servlet/JSP Custom Error Page

落花浮王杯 提交于 2019-12-12 01:34:23
问题 I have a custom error page setup for basic debugging whilst I'm programming and for some reason none of the values from the try catches get through. The error page just says: "Null null null". If anyone can help with this I'd be very grateful. Servlet: package com.atrium.userServlets; import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http

NSInvalidArgumentException not being caught in code

我的未来我决定 提交于 2019-12-12 01:33:44
问题 I'm using selectors to dynamically call functions in Objective-C. My problem is that my @try / @catch block is not catching the exception if I pass an non-existent function name. In the console I get an uncaught NSInvalidArgumentException and further down I get an uncaught NSException . I have tried catching the the two types of exceptions in a standard @try / @catch block but they aren't registering. Xcode won't let me compile if I try to catch NSInvalidArgumentException as it's not a

Try block causing Stream closed IOException

青春壹個敷衍的年華 提交于 2019-12-12 01:32:33
问题 My question is regarding this exception java.io.IOException: Stream closed java.util.zip.InflaterInputStream.ensureOpen(InflaterInputStream.java:67) java.util.zip.InflaterInputStream.read(InflaterInputStream.java:142) java.io.FilterInputStream.read(FilterInputStream.java:107) com.avnet.css.servlet.PartNotificationFileServlet.doGet(PartNotificationFileServlet.java:51) javax.servlet.http.HttpServlet.service(HttpServlet.java:734) javax.servlet.http.HttpServlet.service(HttpServlet.java:847) So we

Finally block is executed only on Debug mode

筅森魡賤 提交于 2019-12-12 01:16:00
问题 Question is taken from here: SO - Timeout in c# tests I created a simple unit test like this: [Timeout(1000)][TestMethod] public void TestMethod1() { try { System.Threading.Thread.Sleep(2000); } finally { Console.WriteLine("Executed"); } } When I run the test, the finally block is not executed. But when I debug it, it does. Why is this happening? 回答1: You specify the test timeout at 1000 ms, while your method sleeps for 2000 ms. This results in your test method being prematurely force-closed

try .. catch with system() command php on laravel 5.0

泪湿孤枕 提交于 2019-12-12 00:43:22
问题 I've a code for command app made on laravel 5.0 with try .. catch and use system command. When there a exception, my catch not work. use Illuminate\Support\Facades\Log; ... try { system('.dump master | sqlite3 ' . $older . ' > ' . storage_path() . '/tmp/' . $tabla . '.sql' ); } catch ( \Exception $e) { Log::alert('Problem import old table '. $tabla . $e->GetMessage()); } I see my error on shell but not write on my own laravel log. (Log:alert) 回答1: You have to gain access over STDERR and,

Using InputMismatchException try/catch block

你离开我真会死。 提交于 2019-12-12 00:33:29
问题 I want to catch any input that is not an Int and prompt for a valid input 3 times. After 3 times, the program will move on and ask for another rating. I can't seem to have the try/catch block repeat or even catch the InputMismatchException. Any suggestions? do { //prompt for rating try { System.out.println("Enter a rating between 0-4 for the Movie of the Week (Enter -1 to stop/exit): "); //capture rating = response.nextInt(); } catch (InputMismatchException err) { System.out.println("Invalid

UIKITThreadAccessException from await Task.Run with a try-catch-finally block

混江龙づ霸主 提交于 2019-12-12 00:17:34
问题 I have the method public async Task doSomething() Inside the method I have the code: ShowSpinner(); await System.Threading.Tasks.Task.Run(() => { try { getValue = value(); } catch(Exception ex) { } finally { HideSpinner(); } }); The ShowSpinner() and HideSpinner() are simply overlays to prevent the user from interacting with the screen and show a spinning wheel to indicate loading. I am getting the error: UIKit Consistency error: you are calling a UIKit method that can only be invoked from

PhpMailer throwing Fatal Exceptions

可紊 提交于 2019-12-12 00:14:36
问题 I have a mailer script that is looping, processing outgoing emails from my server. Occasionally it hangs up with the following error. PHP Fatal error: Uncaught exception 'phpmailerException' with message 'SMTP Error: Data not accepted.' This causes my script to die before the reminder of the messages can complete. Here is the code that kicks off the email. $message = new \PHPMailer(true); $message -> IsSMTP(); try { $message -> SMTPAuth = true; $message -> Host = Config::HOST; $message ->