exception

How to throw a checked exception from a java thread?

断了今生、忘了曾经 提交于 2019-12-27 16:59:49
问题 Hey, I'm writing a network application, in which I read packets of some custom binary format. And I'm starting a background thread to wait for incoming data. The problem is, that the compiler doesn't let me to put any code throwing (checked) exceptions into run() . It says: run() in (...).Listener cannot implement run() in java.lang.Runnable; overridden method does not throw java.io.IOException I want the exception to kill the thread, and let it be caught somewhere in the parent thread. Is

In what ways do C++ exceptions slow down code when there are no exceptions thown?

此生再无相见时 提交于 2019-12-27 13:37:25
问题 I have read that there is some overhead to using C++ exceptions for exception handling as opposed to, say, checking return values. I'm only talking about overhead that is incurred when no exception is thrown. I'm also assuming that you would need to implement the code that actually checks the return value and does the appropriate thing, whatever would be the equivalent to what the catch block would have done. And, it's also not fair to compare code that throws exception objects with 45 state

In what ways do C++ exceptions slow down code when there are no exceptions thown?

只谈情不闲聊 提交于 2019-12-27 13:35:04
问题 I have read that there is some overhead to using C++ exceptions for exception handling as opposed to, say, checking return values. I'm only talking about overhead that is incurred when no exception is thrown. I'm also assuming that you would need to implement the code that actually checks the return value and does the appropriate thing, whatever would be the equivalent to what the catch block would have done. And, it's also not fair to compare code that throws exception objects with 45 state

“NoClassDefFoundError: Could not initialize class” error

拟墨画扇 提交于 2019-12-27 13:03:45
问题 When I run my project, I get numerous outputs of this error: Sep 9, 2009 8:22:23 AM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet Jersey threw exception java.lang.NoClassDefFoundError: Could not initialize class SpringFactory at com.point2.prospect.persistence.hibernate.HibernateTransactionInterceptor.doFilter(HibernateTrans actionInterceptor.java:17) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java

Unhandled exceptions in BackgroundWorker

╄→гoц情女王★ 提交于 2019-12-27 12:15:09
问题 I have a small WinForms app that utilizes a BackgroundWorker object to perform a long-running operation. The background operation throws occasional exceptions, typically when somebody has a file open that is being recreated. Regardless of whether the code is run from the IDE or not .NET pops up an error dialog informing the user that an Unhandled exception has occurred. Compiling the code using the Release configuration doesn't change this either. According to MSDN: If the operation raises an

Handling Java crypto exceptions

独自空忆成欢 提交于 2019-12-27 12:05:00
问题 This, pretty basic, piece of code is quite common when handling encryption\decryption in Java. final Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, key, iv); cipher.doFinal(*something*); These three lines alone, potentially throw six exceptions and I'm not sure what's the cleanest (in terms of code readability) way to handle them. A try with six catch clauses really looks like a smell to me. Are there micropatterns or best practices, I am obviously

Who deletes the memory allocated during a “new” operation which has exception in constructor?

送分小仙女□ 提交于 2019-12-27 11:45:37
问题 I really can't believe I couldn't find a clear answer to this... How do you free the memory allocated after a C++ class constructor throws an exception, in the case where it's initialised using the new operator. E.g.: class Blah { public: Blah() { throw "oops"; } }; void main() { Blah* b = NULL; try { b = new Blah(); } catch (...) { // What now? } } When I tried this out, b is NULL in the catch block (which makes sense). When debugging, I noticed that the conrol enters the memory allocation

alias to chrome console.log

自作多情 提交于 2019-12-27 11:43:29
问题 I would like to know why the follow code doesn't work in the Google Chrome: // creates a xss console log var cl = ( typeof( console ) != 'undefined' ) ? console.log : alert; cl('teste'); output: Uncaught TypeError: Illegal invocation thanks. 回答1: When you write cl(); , you're calling log in the global context. Chrome's console.log doesn't want to be called on the window object. Instead, you can write cl = function() { return console.log.apply(console, arguments); }; This will call log in the

Null check chain vs catching NullPointerException

≡放荡痞女 提交于 2019-12-27 11:03:43
问题 A web service returns a huge XML and I need to access deeply nested fields of it. For example: return wsObject.getFoo().getBar().getBaz().getInt() The problem is that getFoo() , getBar() , getBaz() may all return null . However, if I check for null in all cases, the code becomes very verbose and hard to read. Moreover, I may miss the checks for some of the fields. if (wsObject.getFoo() == null) return -1; if (wsObject.getFoo().getBar() == null) return -1; // maybe also do something with

TAP global exception handler

久未见 提交于 2019-12-27 09:48:22
问题 This code throws an exception. Is it possible to define an application global handler that will catch it? string x = await DoSomethingAsync(); Using .net 4.5 / WPF 回答1: This is actually a good question, if I understood it correctly. I initially voted to close it, but now retracted my vote. It is important to understand how an exception thrown inside an async Task method gets propagated outside it. The most important thing is that such exception needs to be observed by the code which handles