exception-handling

Does re-throwing an exception in PHP destroy the stack trace?

喜夏-厌秋 提交于 2021-02-04 17:35:07
问题 In C#, doing the following would destroy the stack trace of an exception: try{ throw new RuntimeException(); } catch(Exception e){ //Log error //Re-throw throw e; } Because of this, using throw rather than throw e is preferred. This will let the same exception propagate upwards, instead of wrapping it in a new one. However, using throw; without specifying the exception object is invalid syntax in PHP. Does this problem simply not exist in PHP? Will using throw $e as follows not destroy the

How can I swallow all exceptions and protect my application from crashing?

醉酒当歌 提交于 2021-02-04 12:18:30
问题 I've found several C# application crashes in response to error conditions such as obj = null or obj.member = null . A lot of time, the obj from the interface of 3rdPartyApp. And caused both 3rdPartyApp and MyCsApp crashed together. How could I add exception handling in all possible areas so that my application can survive in these disastrous situations? It is a challenge to add try-catch to ALL places, and recover from the situation. How could I accomplish this in a way which is realistic,

Pyramid_exclog : SMTPAuthenticationError: (530, 'Must issue a STARTTLS command first')

点点圈 提交于 2021-01-29 07:35:28
问题 I'm using pyramid_exclog to log exceptions and send those exceptions as email. I'm using Amazon aws SMTP to send emails. But I'm getting the following error: SMTPAuthenticationError: (530, 'Must issue a STARTTLS command first') Here's the code I use: [handler_email_exc_handler] class = handlers.SMTPHandler args = (('email-smtp.us-east-1.amazonaws.com', 587), 'no-reply@company.com', ['me@company.com'], 'Company Exception' ,('<username>','<user_key>'),None) level = ERROR formatter = exc

Pyramid_exclog : SMTPAuthenticationError: (530, 'Must issue a STARTTLS command first')

核能气质少年 提交于 2021-01-29 07:32:48
问题 I'm using pyramid_exclog to log exceptions and send those exceptions as email. I'm using Amazon aws SMTP to send emails. But I'm getting the following error: SMTPAuthenticationError: (530, 'Must issue a STARTTLS command first') Here's the code I use: [handler_email_exc_handler] class = handlers.SMTPHandler args = (('email-smtp.us-east-1.amazonaws.com', 587), 'no-reply@company.com', ['me@company.com'], 'Company Exception' ,('<username>','<user_key>'),None) level = ERROR formatter = exc

How to handle exceptions from native code?

放肆的年华 提交于 2021-01-28 21:47:05
问题 Suppose that my application is composed of 3 components. They are: c++ native library c++ cli managed library, which wraps native library c# gui application. As I understand, any native exception, thrown from a native c++ library will be wrapped with SEHException managed class. I am interested in the next steps, what is recommended to do after the creation of such an exception object. Should I catch all such possible exceptions within the c++ cli managed library then create an appropriate

C++ custom exception message not displaying

半腔热情 提交于 2021-01-28 11:40:36
问题 I am trying to create a custom exception class, throw it, and display the error message, but I am doing something wrong, causing the exception to not get thrown and the message to not get printed. Here's the exception class: class UnbalancedParenthesesException : public std::exception { int line_number {0}; public: UnbalancedParenthesesException(int line_number) : line_number { line_number } {} virtual const char* what() const throw() { std::string exception_message = "Papentheses imbalance

AppDomain.AssemblyLoad event catches all exceptions raised within the event handlers

流过昼夜 提交于 2021-01-28 10:47:35
问题 It seems the .NET AppDomain.AssemblyLoad event catches any exceptions thrown within it's event handlers, not propagating them to the caller who triggered the assembly load (e.g. Assembly.LoadFile() ). My first question is why does this catch all exceptions behavior exist? Microsoft are generally pretty strict about ensuring exceptions always propagate in their BCLs. My second question, is there any way to turn off this behavior? Background: I need to scan assemblies as they are loaded and

Exceptions not caught when linking static libs

匆匆过客 提交于 2021-01-28 06:10:32
问题 I started implementing a try/catch in my program, but when I was testing it, the exceptions were never caught and the program just crashes. Even the simplest use case of a try/catch would fail, i.e try { throw 123; } catch (...) { cerr << "This line doesn't get hit." << endl; } After lots of digging around researching how exceptions work and debugging, I finally found that the issue was because I was linking with specifically -static-libstdc++ which was causing the break. The exceptions work

How to swallow … exception with specific reason

帅比萌擦擦* 提交于 2021-01-28 04:13:07
问题 In this method public static void Detach() { try { using (var master = new DataContext(@"Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True")) { master.ExecuteCommand(string.Format("ALTER DATABASE [{0}] SET OFFLINE WITH ROLLBACK IMMEDIATE", DatabaseFile)); master.ExecuteCommand(string.Format("exec sp_detach_db '{0}'", DatabaseFile)); } } catch (Exception e) { ... // add to log } } I can receive exception System.Data.SqlClient.SqlException (0x80131904): The

Flask and sys.excepthook

左心房为你撑大大i 提交于 2021-01-28 02:08:30
问题 I want to add global exception handling object to my Flask webproject. In main module, where application class is created I've added code to override sys.excepthook . Here is simple test code: import sys def my_exception_hook(exception_type, value, traceback): print "My exception handler" print " Exception type:", exception_type print " Exception instance:", value print " Traceback:", traceback sys.__excepthook__(exception_type, value, traceback) sys.excepthook = my_exception_hook from flask