exception-handling

How to get a complete exception stack trace in Python

牧云@^-^@ 提交于 2019-12-17 21:58:03
问题 The following snippet: import traceback def a(): b() def b(): try: c() except: traceback.print_exc() def c(): assert False a() Produces this output: Traceback (most recent call last): File "test.py", line 8, in b c() File "test.py", line 13, in c assert False AssertionError What should I use if I want the complete stack trace including the call to a? If it matters I have Python 2.6.6 edit: What I'd like to get is the same information I'd get if I left the try except out and let the exception

error handling in asynchronous node.js calls

这一生的挚爱 提交于 2019-12-17 21:44:57
问题 I'm new to node.js although I'm pretty familiar with JavaScript in general. My question is regarding "best practices" on how to handle errors in node.js. Normally when programming web servers, FastCGI servers or web pages in various languages I'm using Exceptions with blocking handlers in a multi-threading environment. When a request comes in I usually do something like this: function handleRequest(request, response) { try { if (request.url=="whatever") handleWhateverRequest(request, response

JSF 1.2 Exception Handling

社会主义新天地 提交于 2019-12-17 21:35:24
问题 I am working on exception handling in our Application. I used try catch blocks to catch the exceptions occured in my code and i also could handle the time out exceptions by writing a listener and registering the listener in "faces-config.xml". But i am facing problems in catching unexpected errors like "NullPointerException" in constructor or error Codes 500, 400 etc. i used the tags in the "web.xml" <error-page> <exception-type>java.lang.Exception</exception-type> <location>/sc00/ErrorPage

Is there any way to get some information at least for catch(…)?

独自空忆成欢 提交于 2019-12-17 20:52:33
问题 Is there any way to get at least some information inside of here? ... catch(...) { std::cerr << "Unhandled exception" << std::endl; } I have this as a last resort around all my code. Would it be better to let it crash, because then I at least could get a crash report? 回答1: No, there isn't any way. Try making all your exception classes derive from one single class, like std::exception , and then catch that one. You could rethrow in a nested try , though, in an attempt to figure out the type.

How to define a global page when requested page or method is not found?

♀尐吖头ヾ 提交于 2019-12-17 20:29:54
问题 I know how to fine a global error redirect page in our defined package when exception encountered that just by adding the following configuration in the parent package in struts.xml : <global-results> <result name="error">/error.jsp</result> </global-results> <global-exception-mappings> <exception-mapping exception="java.lang.Exception" result="error" /> </global-exception-mappings> But It seems to not able to catch those exceptions like requested resources, methods, pages are not found, I

When is it appropriate to use error codes?

↘锁芯ラ 提交于 2019-12-17 19:37:35
问题 In languages that support exception objects (Java, C#), when is it appropriate to use error codes? Is the use of error codes ever appropriate in typical enterprise applications? Many well-known software systems employ error codes (and a corresponding error code reference). Some examples include operating systems (Windows), databases (Oracle, DB2), and middle-ware products (WebLogic, WebSphere). What benefits do error codes provide? What are the disadvantages to using error codes? 回答1: WITHIN

python isinstance vs hasattr vs try/except: What is better?

懵懂的女人 提交于 2019-12-17 19:14:27
问题 I am trying to figure out the tradeoffs between different approaches of determining whether or not with object obj you can perform action do_stuff() . As I understand, there are three ways of determining if this is possible: # Way 1 if isinstance(obj, Foo): obj.do_stuff() # Way 2 if hasattr(obj, 'do_stuff'): obj.do_stuff() # Way 3 try: obj.do_stuff() except: print 'Do something else' Which is the preferred method (and why)? 回答1: I believe that the last method is generally preferred by Python

Exception handling in Grails controllers

微笑、不失礼 提交于 2019-12-17 18:35:02
问题 I know how to do generic exception handling in Grails using UrlMappings and an ErrorController for generic exception handling, so that if an exception escapes a controller the user will be sent to a generic error page and the exception will be logged. I also know how to use try/catch blocks to handle specific exceptions and attempt to recover from them. But in most controllers, I just want to give the user a slightly more specific error message if an exception occurs. So in the create action,

how to handle exceptions in junit

十年热恋 提交于 2019-12-17 18:34:37
问题 I wrote some test cases to test some method. But some methods throw an exception. Am I doing it correctly? private void testNumber(String word, int number) { try { assertEquals(word, service.convert(number)); } catch (OutOfRangeNumberException e) { Assert.fail("Test failed : " + e.getMessage()); } } @Test public final void testZero() { testNumber("zero", 0); } If I pass -45 , it will fail with OutOfRangeException but I am not able to test specific exception like @Test(Expected...) 回答1: An

Graceful exception handling in Swing Worker

两盒软妹~` 提交于 2019-12-17 18:26:15
问题 I am using threading in application through Swing Worker class. It works fine, yet I have a bad feeling about showing an error message dialog in try-catch block. Can it potentially block the application? This is what it looks right now: SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { // Executed in background thread public Void doInBackground() { try { DoFancyStuff(); } catch (Exception e) { e.printStackTrace(); String msg = String.format("Unexpected problem: %s", e .toString