exception-handling

How to convert functions raising exceptions to functions returning Either?

﹥>﹥吖頭↗ 提交于 2019-12-05 21:28:59
问题 Suppose I have a few functions that raise exceptions. I am wrapping them to return Either[Throwable, <function return type>] . (Let's assume I need Either rather than Try ). def fooWrapper(arg1: FooArg1, arg2: FooArg2) = try Right(foo(arg1, arg2)) catch { case NonFatal(e) => Left(e) } def barWrapper(arg1: BarArg1, arg2: BarArg2, a3: BarArg3) = try Right(bar(arg1, arg2, artg3)) catch { case NonFatal(e) => Left(e) } ... Now I would like to write a generic wrapper to get rid of the bolierpllate

On Error Resume Next in Javascript?

折月煮酒 提交于 2019-12-05 21:13:22
问题 Does try ... catch(e) provide the same service as On Error Resume Next in VB? I have a page which uses several JQuery plugins as well as some functions I have written myself. It would take a lot of work to address all possible exceptions. For now, I want to tell the script not to break on would be fatal errors. How do I do that when I'm using plugins? 回答1: Yes, try / catch provides a way to capture errors, though unlike On Error Resume Next you choose to deal with the error in the catch block

The process cannot access the file because it is being used by another process (File is created but contains nothing)

旧巷老猫 提交于 2019-12-05 21:12:05
问题 using System.IO; class test { public static void Main() { string path=@"c:\mytext.txt"; if(File.Exists(path)) { File.Delete(path); } FileStream fs=new FileStream(path,FileMode.OpenOrCreate); StreamWriter str=new StreamWriter(fs); str.BaseStream.Seek(0,SeekOrigin.End); str.Write("mytext.txt........................."); str.WriteLine(DateTime.Now.ToLongTimeString()+" "+DateTime.Now.ToLongDateString()); string addtext="this line is added"+Environment.NewLine; File.AppendAllText(path,addtext); /

Java exception handling - catching superclass exception

耗尽温柔 提交于 2019-12-05 21:01:58
I have a question on handling exception in web application. Often I hear catching the super class Exception is a bad idea. Often I write codes to catch all exceptions in struts action / java servlet classes. try { // call business facade // business facade calls DAO // any exception from DAO bubbles up } catch (Exception e) { log.error("error", e); } If we do not catch superclass Exception. How do we handle any unexpected runtime errors and logged them appropriately You can setup a DefaultUncaughtExceptionHandler for your project to deal with uncaught exceptions. For example, this is a piece

How do I handle exceptions?

北战南征 提交于 2019-12-05 20:57:41
问题 Angular has a great $exceptionHandler. Is there anything like this for react.js? I would like to log my errors to an external API. Examples: https://github.com/occ/TraceKit http://trackjs.com/ https://plus.google.com/+PaulIrish/posts/12BVL5exFJn 回答1: There's no magic like in angular. If there's an uncaught error, it propagates up the scopes until it hits window, and then an error event is emitted – the same behavior as an error without react. var App = React.createClass({ render: function(){

Android: handle unexpected internet disconnect while downloading data

℡╲_俬逩灬. 提交于 2019-12-05 20:53:55
问题 I have here a function that downloads data from a remote server to file. I am still not confident with my code. My question is, what if while reading the stream and saving the data to a file and suddenly I was disconnected in the internet, will these catch exceptions below can really catch that kind of incident? If not, can you suggest how to handle this kind of incident? Note: I call this function in a thread so that the UI won't be blocked. public static boolean getFromRemote(String link,

How to suppress displaying the parent exception (the cause) for subsequent exceptions

北城以北 提交于 2019-12-05 20:15:48
问题 I'm aware of raise ... from None and have read How can I more easily suppress previous exceptions when I raise my own exception in response?. However, how can I achieve that same effect (of suppressing the "During handling of the above exception, another exception occurred" message) without having control over the code that is executed from the except clause? I thought that sys.exc_clear() could be used for this, but that function doesn't exist in Python 3. Why am I asking this? I have some

Exception handling in ASP.NET Webforms

…衆ロ難τιáo~ 提交于 2019-12-05 20:14:43
问题 What is the preferred method for handling exceptions in ASP.NET Webforms? You have the Page_Error method that you add (I think) at web.config level, and the entire site gets redirected there when an error occurs. Does that mean you shouldn't use try-catch anywhere in a webforms application? (Assuming you don't want to hide any errors) 回答1: Only catch the errors you can handle. If you can handle them in a manner that allows the page to continue loading then do so. Any other exception that

unhandled exceptions in a windows service

旧城冷巷雨未停 提交于 2019-12-05 19:59:18
I have created a .net c# windows service that runs multiple tasks. I included exception handling in it but I would like to set up a global handler to catch unhandled exceptions in the windows service, how can I do this? I included exception handling in it but I would like to set up a global handler to catch unhandled exceptions in the windows service You could use AppDomain.UnhandledException . In your case however, your entire call to your service can be wrapped in a try/catch block. Since you haven't provided details for what you plan to do with this unhandled exception, your correct path I

Laravel 5 override exception handler

跟風遠走 提交于 2019-12-05 18:55:18
I'd like to know if it's possible to override the application exception handler class in Laravel 5 without extending it to another class. Maybe a better way of saying it is that I'd like it so that not App\Exceptions\Handler will be called on an exception but one of my own handlers. Thanks in advance. As mentioned before by Digitlimit here Laravel ships with default ExceptionHandler which can be overwritten. There's two ways you can do so: Adjusting the implemented ExceptionHandler Laravel 5.8 ships with a default ExceptionHandler implemented in app/Exceptions/Handler.php . This class extends