throw

catching error event message from firefox

你说的曾经没有我的故事 提交于 2019-12-05 20:34:12
I can't find a way to catch the error message under firefox: window.addEventListener("error", handleException, false); ... function handleException(e) { alert(e); return false; } ... <script> throw new Error('sdasd'); </script> This enters very well the handleException method however the e parameter is an error event under firefox and I don't know how to get the associated message . In chrome for instance, I get either the message through e.message because after the error bubbles up to not being caught, there's an automatic error fired at window level (See this fiddle : the final error is

Throw VS rethrow : same result?

怎甘沉沦 提交于 2019-12-05 16:43:33
问题 refering to a lot of documentation on the net, particularly on SO, eg : What is the proper way to re-throw an exception in C#? there should be a difference between "throw e;" and "throw;". But, from : http://bartdesmet.net/blogs/bart/archive/2006/03/12/3815.aspx, this code : using System; class Ex { public static void Main() { // // First test rethrowing the caught exception variable. // Console.WriteLine("First test"); try { ThrowWithVariable(); } catch (Exception ex) { Console.WriteLine(ex

Function exceptions specification and standard exceptions - foo() throw(Exception)

妖精的绣舞 提交于 2019-12-05 16:06:15
In C++ you may declare function with exception specification like this: int foo() const throw(Exception); I found those two links: http://www.cplusplus.com/doc/tutorial/exceptions/ and http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr156.htm But several things end up unanswered... Question 1: why to add exception specification? Will it bring any performance increase? What will be different for compiler? Because it seems just like an information for programmer to me. Question 2: what will happend (what should happen) if I

Best way to handle errors from async closures in Swift 2?

◇◆丶佛笑我妖孽 提交于 2019-12-05 11:13:08
I'm using a lot of async network request (btw any network request in iOS need to by async) and I'm finding way to better handle errors from Apple's dataTaskWithRequest which not supports throws . I have code like that: func sendRequest(someData: MyCustomClass?, completion: (response: NSData?) -> ()) { let request = NSURLRequest(URL: NSURL(string: "http://google.com")!) if someData == nil { // throw my custom error } let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in // here I want to handle Apple's error } task.resume() } I need to parse my possible

Why do I always get “terminate called after throwing an instance of…” when throwing in my destructor?

心已入冬 提交于 2019-12-05 08:19:49
I'm trying to write a unit test that detects an invalid use of the lock() feature of my class. In order to do so, I want to use the destructor and throw an exception from there. Unfortunately, instead of catching the exception, g++ decides to call std::terminate(). There is a very simplified version of the class: class A { public: A() : f_lock(0) {} ~A() { if(f_lock) throw my_exception("still locked"); } lock() { ++f_lock; } unlock() { --f_lock; } private: int f_lock; }; There is a valid test: A *a = new A; a->lock(); ... a->unlock(); delete a; There is the invalid test I'm trying to write: A

Catch/Modify (Message)/Rethrow Exception of same type

不想你离开。 提交于 2019-12-05 07:09:39
I want a central place to extract information from an exception, set all the information I need to its message parameter and then rethrow that information as an Exception of the same type. The better solution probably would be to do this at the place where the exception is finally being handled (and its message logged), but.. I have control over the place throwing the exception, and not over the place that receives the exception and only logs its Message content. Apart from that design decision and given that message is a readonly property, I would have (?) to create a new Exception object in

Throw and preserve stack trace not as expected as described by Code Analysis

天涯浪子 提交于 2019-12-05 03:57:24
Doing a code analysis gave me item CA2200: CA2200 Rethrow to preserve stack details 'func()' rethrows a caught exception and specifies it explicitly as an argument. Use 'throw' without an argument instead, in order to preserve the stack location where the exception was initially raised. I have implemented the suggestion, but I seem to get the same stack trace regardless. Here is my test code and output (the white space is intended to give obvious line numbers): Expected error at Line 30 using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using

Destructor that calls a function that can throw exception in C++

北城以北 提交于 2019-12-04 18:31:59
问题 I know that I shouldn't throw exceptions from a destructor. If my destructor calls a function that can throw an exception, is it OK if I catch it in the destructor and don't throw it further? Or can it cause abort anyway and I shouldn't call such functions from a destructor at all? 回答1: Yes, that's legal. An exception must not escape from the destructor, but whatever happens inside the destructor, or in functions it calls, is up to you. (Technically, an exception can escape from a destructor

Can you throw within a conditional expression? (was: How can bounds-checking be extended to multiple dimensions?)

只谈情不闲聊 提交于 2019-12-04 17:13:50
Note: I solved the original problem by realizing a completely different one. See the addendum for the new actual problem, but you can read the previous part for context. This is an extension of one of my previous posts . I made a container class based on that answer: template < typename T, unsigned N0, unsigned ...N > struct array_md { // There's a class template specialization with no extents. // Imagine the various N... components are bracket-enclosed instead // of comma-separated. And if "N..." is empty, then we just have "T" // as the "direct_element_type". (I actually use recursive class

NoSuchBeanDefinitionException at least 1 bean which qualifies as autowire candidate for this dependency

蹲街弑〆低调 提交于 2019-12-04 10:41:24
I have problem with Spring framework, I was searching for solution long time, but any result. When I Deploying an application, I get Exception: 14.11.2012 0:37:23 org.apache.catalina.core.ApplicationContext log INFO: No Spring WebApplicationInitializer types detected on classpath 14.11.2012 0:37:23 org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring root WebApplicationContext 14.11.2012 0:37:24 org.apache.catalina.core.StandardContext listenerStart SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context