exception-handling

Is it possible to write/wrap the exception handling components (try,catch) in different class?

人盡茶涼 提交于 2019-12-21 12:36:56
问题 This is about wrapping the exception handling logic in some sort of class. While writing c++ code, many time we need to catch many type/variants of exception depending on what client throw. This lead us to write similar types of code(many times) in catch() clause. In below sample example, I have written the function(), which can throw exception in the many possible form. I wanted to know is it possible to write/wrap such logic in the form of class so that end user would have to write similar

How to debug “The type initializer for 'my class' threw an exception”

烈酒焚心 提交于 2019-12-21 12:16:22
问题 I am getting the exception: The type initializer for 'my class' threw an exception. in my browser after running my web application. Since this seems to be an error message generated from the view (.aspx), there is no way I can see the stack trace or any log for the source of this error. I have read a bit around the net and one solution to debugging is to throw a TypeInitializationException and then looking at the inner exception to find out what was wrong. How can I do this when I don't know

Where can I find information about C++/STL method Exception guarantees?

牧云@^-^@ 提交于 2019-12-21 09:34:36
问题 I was writing code with exception handling the other day, and I had a few questions about exceptions, their guarantees and throwables. Basically, say you have: class X { string m_str; X() : m_str("foo")//what if this throws? { ifstream b("a.in")//what if this throws? } And after running through all the articles I could find, I still have no idea what is the clean way to handle this. Say I have a code like: { ... X myInstanceOfClassX; ... } Should I wrap the code in catch(exception &) ? And if

Previous error being masked by current exception context

ε祈祈猫儿з 提交于 2019-12-21 08:23:55
问题 The following is an example I found at the website for Doug Hellman in a file named "masking_exceptions_catch.py". I can't locate the link at the moment. The exception raised in throws() is discarded while that raised by cleanup() is reported. In his article, Doug remarks that the handling is non-intuitive. Halfway expecting it to be a bug or limitation in the Python version at the time it was written (circa 2009), I ran it in the current production release of Python for the Mac (2.7.6). It

Previous error being masked by current exception context

我怕爱的太早我们不能终老 提交于 2019-12-21 08:22:50
问题 The following is an example I found at the website for Doug Hellman in a file named "masking_exceptions_catch.py". I can't locate the link at the moment. The exception raised in throws() is discarded while that raised by cleanup() is reported. In his article, Doug remarks that the handling is non-intuitive. Halfway expecting it to be a bug or limitation in the Python version at the time it was written (circa 2009), I ran it in the current production release of Python for the Mac (2.7.6). It

Do uncatchable exceptions exist in Javascript?

ⅰ亾dé卋堺 提交于 2019-12-21 07:31:09
问题 Do any javascript runtimes (browsers, Node, etc.) ever throw uncatchable exceptions? Are any and all exceptions ever encountered in a javascript environment catchable in a try/catch statement? 回答1: If by exceptions you mean any exceptional condition that breaks your script, then all of them can throw uncatchable exceptions, since most syntax errors aren't catchable. Only syntax errors from dynamically evaluated code ( eval , new Function ) can be caught. try { :( } catch(e) { } // uncatchable

FileNotFoundException vs. NoSuchFileException

喜夏-厌秋 提交于 2019-12-21 07:27:30
问题 I noticed another Java exception for indicating that file does not exist - NoSuchFileException . I was tasked to refactor a certain api which throws both of these from differen methods and I would like to use just one. Should I map NoSuchFileException to file to FileNotFoundException ? Should I use NoSuchFileException instead of FileNotFoudnException because it is more specific? EDIT: Updated the question. I read the documentation before posting this question and know the basic difference. I

Why is there no MonadMask instance for ExceptT?

ぐ巨炮叔叔 提交于 2019-12-21 07:11:13
问题 Edward Kmett's exceptions library does not provide a MonadMask instance for ExceptT. Ben Gamari once asked about this and then concluded that it was explained by the documentation. This is the closest relevant-looking passage I can find: Note that this package does provide a MonadMask instance for CatchT . This instance is only valid if the base monad provides no ability to provide multiple exit. For example, IO or Either would be invalid base monads, but Reader or State would be acceptable.

Should I put throws IllegalArgumentException at the function?

瘦欲@ 提交于 2019-12-21 07:08:20
问题 I'm building a scientific software with lots of calculations and of course arguments can have wrong lengths etc... So I used IllegalArgumentException class as it seemed right name for the issue, but should I put the throws IllegalArgumentException at the function definition ? I am asking this because after I wrote it, the Eclipse Editor didn't ask me to surround the function with try and catch. I thought this is how try and catch were enforced. I've read the Exception handling tutorial at

PHP - Converting all Errors to Exceptions - Good or Bad?

独自空忆成欢 提交于 2019-12-21 07:05:28
问题 I was wondering if it's considered a bad practice to globally convert all PHP Errors to Exceptions. Something like the following would be used: function exception_error_handler($errno, $errstr, $errfile, $errline ) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); return false; } I suppose the assumption is that you can just start using "try/catch" around certain pieces of code that would normally throw Errors. If it's not a case of Good/Bad, what are some of the Gotchas