exception-handling

C#/Java “Try/Finally/Catch” equivalent construct in Delphi

让人想犯罪 __ 提交于 2019-12-17 16:08:06
问题 In Delphi, how can you use try, finally, and catch together? A Java/C# equivalent would look something like: try { // Open DB connection, start transaction } catch (Exception e) { // Roll back DB transaction } finally { // Close DB connection, commit transaction } If you try this in Delphi, you can either use try/finally or try/except; but never all three together. I would like code like the following (which doesn't compile): try // Open DB connection, start transaction except on e: Exception

How does an exception specification affect virtual destructor overriding?

那年仲夏 提交于 2019-12-17 16:07:11
问题 The C++ Standard states the following about virtual functions that have exception specifications: If a virtual function has an exception-specification , all declarations, including the definition, of any function that overrides that virtual function in any derived class shall only allow exceptions that are allowed by the exception-specification of the base class virtual function (C++03 §15.4/3). Thus, the following is ill-formed: struct B { virtual void f() throw() { } // allows no exceptions

'sys.excepthook' and threading

蓝咒 提交于 2019-12-17 15:55:19
问题 I am using Python 2.5 and trying to use a self-defined excepthook in my program. In the main thread it works perfectly fine. But in a thread started with the threading module the usual excepthook is called. Here is an example showing the problem. Uncommenting the comment shows the desired behaviour. import threading, sys def myexcepthook(type, value, tb): print 'myexcepthook' class A(threading.Thread, object): def __init__(self): threading.Thread.__init__(self, verbose=True) # raise Exception

Throwing C++ exceptions across DLL boundaries

孤街浪徒 提交于 2019-12-17 15:53:50
问题 I've read various things about how one should not allocate heap memory in one DLL and deallocate it from outside that DLL. But what about throwing an exception object that is a just a temporary (as most exception objects are)? E.g.: throw my_exception( args ); // temporary: no heap allocation When the exception object is caught outside the DLL, the destructor for that object will eventually be executed and the non-heap memory for the object will be reclaimed. Is that OK since it's not heap

Handle TokenMismatchException in laravel 5

前提是你 提交于 2019-12-17 15:35:12
问题 I need to handle TokenMismatchException in laravel 5 such a way that if token does not match it will show some message to user instead of TokenMismatchException error. 回答1: You can create a custom exception render in the App\Exceptions\Handler class (in the /app/Exceptions/Handler.php file). For example, to render a different view when for the TokenMismatchException error, you can change the render method to something like this: /** * Render an exception into an HTTP response. * * @param

What are the principles guiding your exception handling policy? [closed]

一个人想着一个人 提交于 2019-12-17 15:29:54
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . There is a lot of relativity involved in working with exceptions. Beyond low level APIs where exceptions cover errors raised from hardware and the OS there is a shady area where the programmer decides what constitutes an exception and what is a normal condition. How do you

c++ stack trace from unhandled exception?

六眼飞鱼酱① 提交于 2019-12-17 15:27:46
问题 This question has been asked before and there have been windows-specific answers but no satisfactory gcc answer. I can use set_terminate() to set a function that will be called (in place of terminate() ) when an unhandled exception is thrown. I know how to use the backtrace library to generate a stack trace from a given point in the program. However, this won't help when my terminate-replacement is called since at that point the stack has been unwound. Yet if I simply allow the program to

Example of “using exceptions to control flow” [closed]

夙愿已清 提交于 2019-12-17 14:04:09
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . What would a piece of code which "uses exceptions to control flow" look like? I've tried to find a direct C# example, but cannot. Why is it bad? Thanks 回答1: Bad The below code catches an exception that could easily be avoided altogether. This makes the code more difficult to

Wrong line number on stack trace

夙愿已清 提交于 2019-12-17 10:26:52
问题 I have this code try { //AN EXCEPTION IS GENERATED HERE!!! } catch { SqlService.RollbackTransaction(); throw; } Code above is called in this code try { //HERE IS CALLED THE METHOD THAT CONTAINS THE CODE ABOVE } catch (Exception ex) { HandleException(ex); } The exception passed as parameter to the method "HandleException" contains the line number of the "throw" line in the stack trace instead of the real line where the exception was generated. Anyone knows why this could be happening? EDIT1 Ok

Asp.net mvc override OnException in base controller keeps propagating to Application_Error

可紊 提交于 2019-12-17 10:18:24
问题 I am trying to return a view not issue a redirect to the user based on certain errors that could occur from my application, I want to handle the errors + log them inside my base controller, I do not want the error to propagate up to my Global.asax - Application_Error() method as I want this method to handle any other errors inside my app e.g. user enters a bogus URL, has anyone found a way around this? NOTE: I have left my commented code as I had a workaround for some issues, this also shows