exception-handling

Using AssertionError and assertions in java

五迷三道 提交于 2019-12-18 13:08:22
问题 I use assertions in Java in a standard way, having them turned on in my IDE. So they are not part of production release. Lately I have been seeing code examples with throw new AssertionError() and I started thinking about the situation where AssertionError should be used instead of assertion. My guess is that main difference is the optionality of asserts so they don't slow down the production performance and so they can occur quite often in the code, but fixing hardly reproducible bugs

Why String.indexOf do not use exception but return -1 when substring not found?

点点圈 提交于 2019-12-18 12:56:21
问题 Why String.indexOf do not use exception but return -1 when substring not found? The purpose of this question is: when we start custom exception. I believe avoid the need to return special error code is right design path. What's your opinion? 回答1: As a rule of thumb, if the purpose of a method is to check for something, then the lack of that something shouldn't be an exception. If the method is assuming that something is true, then the absence of that something would be an exception. Thus

Is there a global exception handler in Windows store apps?

泄露秘密 提交于 2019-12-18 12:53:07
问题 For unhandled exceptions, at least, I'd like to be able to catch the details and write them out to a file for potential subsequent "debugging forensics." There is no "OnTerminating" event in Windows store apps; is there a suitable place/way to accomplish such? UPDATE See my comment below. Here is an addition that won't fit below: Even when removing the xaml snippet, I still get that err msg, and even after Cleaning and Rebuilding...??? 2-clicking the err msg just takes me to the top of App

How can I Rethrow an exception from catch block in Powershell?

廉价感情. 提交于 2019-12-18 12:43:34
问题 Should I approach the exception handling in the same manner as .Net? Then, how can I re-throw an exception from catch block in Powershell? 'throw' is enoungh or 'throw $_' would be better? 回答1: If you would like to re-throw original exception you could use throw (most common), or throw $_ , or throw $_.Exception ps: inside catch variable $_ is not exception by itself, but System.Management.Automation.ErrorRecord that contains Exception Note The throw keyword at PowerShell behaves differently

.NET and C# Exceptions. What is it reasonable to catch

五迷三道 提交于 2019-12-18 12:23:36
问题 Disclaimer, I'm from a Java background. I don't do much C#. There's a great deal of transfer between the two worlds, but of course there are differences and one is in the way Exceptions tend to be thought about. I recently answered a C# question suggesting that under some circstances it's reasonable to do this: try { some work } catch (Exeption e) { commonExceptionHandler(); } (The reasons why are immaterial). I got a response that I don't quite understand: until .NET 4.0, it's very bad to

.NET and C# Exceptions. What is it reasonable to catch

て烟熏妆下的殇ゞ 提交于 2019-12-18 12:23:01
问题 Disclaimer, I'm from a Java background. I don't do much C#. There's a great deal of transfer between the two worlds, but of course there are differences and one is in the way Exceptions tend to be thought about. I recently answered a C# question suggesting that under some circstances it's reasonable to do this: try { some work } catch (Exeption e) { commonExceptionHandler(); } (The reasons why are immaterial). I got a response that I don't quite understand: until .NET 4.0, it's very bad to

Exceptions by DataContext

拥有回忆 提交于 2019-12-18 12:22:34
问题 I've been doing some searching on the internet, but I can't seem to find the awnser. What exceptions can a DataContext throw? Or to be more specific, what exceptions does the DataContext.SubmitChanges() method throw? EDIT For reference, here a List of possible known exceptions that could be thrown by the L2S DataContext: SqlException ChangeConflictException DuplicateKeyException ForeignKeyReferenceAlreadyHasValueException OutOfMemoryException (when not correctly disposing the DataContext) 回答1

Try/Catch with jquery ajax request

折月煮酒 提交于 2019-12-18 12:18:37
问题 I am trying to build a Google Chrome extension that makes an ajax request. Something similar to the GMail Checker extension. The problem is that when I do the request using jquery, and I put in the wrong username/password, it fails silently, with the error callback function ignored. If I move the ajax call out of the background.html script (where I can't see the requests in the developer window), to the options.html script, I get a dialog box to re-authenticate. If I hit cancel, THEN the

Not creating queues automatically in NServiceBus

荒凉一梦 提交于 2019-12-18 11:51:51
问题 I'm running NServiceBus 3.0.0 rc2 but when I start the application (as local admin) without pre-creating the MSMQ's it errors with : The queue does not exist or you do not have sufficient permissions to perform the operation. This was not happening using NServiceBus 2.6. Below is my config: var bus = Configure.With() .Log4Net() .NinjectBuilder() .XmlSerializer() .DefiningCommandsAs(t => typeof(ICommand).IsAssignableFrom(t)) .DefiningEventsAs(t => typeof(IEvent).IsAssignableFrom(t))

Get detail messages of chained exceptions Java

放肆的年华 提交于 2019-12-18 11:48:49
问题 I'd like to know how I could I thorw a "final" Exception , containing a detail message with all the detail messages of a number of chained exceptions. For example suppose a code like this: try { try { try { try { //Some error here } catch (Exception e) { throw new Exception("FIRST EXCEPTION", e); } } catch (Exception e) { throw new Exception("SECOND EXCEPTION", e); } } catch (Exception e) { throw new Exception("THIRD EXCEPTION", e); } } catch (Exception e) { String allMessages = //all the