exception-handling

What is the best exception handling strategy within error logging classes?

江枫思渺然 提交于 2019-12-24 11:19:00
问题 I am writing an error logging set of classes which will log to file, event log etc. What exception handling should be performed within these classes? For instance, say I have a LogError method, which is called from exception handlers, and writes to file. What is considered the best thing to do, should an error occur? Obviously, I should make these methods as fail safe as possible, but problems can always occur. 回答1: Generally I output to stderr as much information as possible in that case,

Exception not caught in Task.Run wrapped method

痴心易碎 提交于 2019-12-24 10:48:06
问题 New to async await integration in C# 5. I'm working with some basic Task based methods to explore async await and the TPL. In this example below I'm calling a web service with a timeout of 5 seconds. If the timeout expires it should throw an exception so I can return false from the method. However, the timeout never occurs, or maybe it does but the Task never returns. public static Task<bool> IsConnectedAsync() { return Task.Run(() => { try { using (WSAppService.AppService svc = new

Math.sqrt(-5) -> Force Exception in JSP?

空扰寡人 提交于 2019-12-24 09:51:07
问题 I've 3 .jsp files. index.jsp and sqrtcalculator.jsp and error.jsp. In index.jsp there's a text field and a button. In sqrtcalculator.jps there's the, well, calculator. Now, when I leave the field empty and press the button, an expection is called, because the field is empty. And I can then reroute to an individual error.jsp site to display the errors, and exception stack like <%= request.getAttribute("javax.servlet.error.request_uri") %> <%= exception.getMessage() %> <%= exception %> etc.

Catching an unhandled exception prior to it reaching Application level

不问归期 提交于 2019-12-24 09:23:42
问题 We use the Dispatcher to catch any unhandled exceptions in our WPF app. This is defined in our app.xaml.cs file and it works very well. However we have a situation where we want to detect and trap any unhandled exceptions that happen in a specific WPF User Control. We would like to be able to intercept any unhandled erros related to that control prior to them being received and handled by the handler at the app level. When we try to set up a handler for the User Control dispatcher the

How to simulate caught and logged exceptions inside a method and create JUnit tests

我只是一个虾纸丫 提交于 2019-12-24 09:17:11
问题 I have to write JUnit test cases for existing code where I do not have the liberty / opportunity to re-write the actual code. In many of these classes, the methods catch an exception internally and just log it. And the exceptions are not based on any parameters which could be manipulated to attempt to throw the exception, but are thrown by the code inside the method - e.g. - the method may open a file and catch IOException and just log it. Basically, many of the methods just eat all the

Catching mysql connection error

让人想犯罪 __ 提交于 2019-12-24 09:12:30
问题 So i have simple code: try{ $mysqli = new mysqli($sql_login['host'], $sql_login['user'], $sql_login['password'] , $sql_login['database'], $sql_login['port'] ); if($mysqli->connect_errno){ throw new Exception("Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error); } } catch (Exception $e) { echo 'Exception: ', $e->getMessage(), "\n"; } the problem is that php returns error and also the exception. Is there something like in java with throw and throws? 回答1: You

Task.WaitAll hang when one task throws and another syncs with the first task

爷,独闯天下 提交于 2019-12-24 08:48:01
问题 What should be expected from Task.WaitAll(t1, t2) , when t2 's execution syncs with t1 , but t1 throws an exception before the point it syncs to t2 ? In this case, it's obvious that t2 will never finish. However since t1 throws an exception, I expected Task.WaitAll(t1,t2) to return with aggregated exception indicating one of the task fails. However this is not the case. It turns out that Task.WaitAll hangs waiting forever. I can argue for this behavior that Task.WaitAll does what it claims to

Where did the exception assistant go for Visual Studio 2015?

那年仲夏 提交于 2019-12-24 07:48:23
问题 For a handled exception in Visual Studio 2013 I could view the exception dialog in a catch block by clicking the red exception helper icon. In Visual Studio 2015 this is missing. The dialog still shows when the exception is thrown, so that is not the issue. Though there is a workaround in this answer, this doesn't provide the functionality of the exception dialog (e.g. copy to clipboard). 回答1: Apparently it's no longer there, so you have to watch $exception , which always has the current

Wrapping an exception and hiding sensitive details

梦想与她 提交于 2019-12-24 07:39:21
问题 How can I hide sensitive details in a java exception? Is it only possible to do by wrapping the exception with another? If so, how exactly does this hide the exception because if I put a watch on the exception @ debug time, I'd be able to see all information on the old exception and the one I am wrapping it with, no? BTW, this is not like ASP.NET where I can call Response.Write("") to write a friendly string to the webpage/response stream. This is a java plugin, in a java web-based app (the

Possible to render and raise exception in Rails controller?

孤人 提交于 2019-12-24 07:28:47
问题 I have been fighting with this for some hours now. I have a controller action that I want to render a page and then raise an exception automatically. I couldn't find much information on this that makes me think that I am looking for the wrong thing. Is something like the below possible? class UsersController < ActionController::Base def new # .. do stuff begin UserMailer::send_confirmation_link(@user) rescue StandardError => e render 'email_error' raise(e) end # .. other stuff end end In this