exception-handling

Checked vs Unchecked exception

怎甘沉沦 提交于 2019-12-28 01:00:28
问题 I've studied that: With an unchecked exception, however, the compiler doesn't force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method. what its mean? according to that code there is no need to put try catch block in code, but i've seen compiler forces to put the code in try catch block. I'm very confused what

Do you (really) write exception safe code? [closed]

青春壹個敷衍的年華 提交于 2019-12-27 16:08:00
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Exception handling (EH) seems to be the current standard, and by searching the web, I can not find any novel ideas or methods that try

Do you (really) write exception safe code? [closed]

醉酒当歌 提交于 2019-12-27 16:07:50
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Exception handling (EH) seems to be the current standard, and by searching the web, I can not find any novel ideas or methods that try

Are destructors called after a throw in C++?

独自空忆成欢 提交于 2019-12-27 12:17:07
问题 I ran a sample program and indeed destructors for stack-allocated objects are called, but is this guaranteed by the standard? 回答1: Yes, it is guaranteed (provided the exception is caught), down to the order in which the destructors are invoked: C++11 15.2 Constructors and destructors [except.ctor] 1 As control passes from a throw-expression to a handler, destructors are invoked for all automatic objects constructed since the try block was entered. The automatic objects are destroyed in the

Why use finally in C#?

点点圈 提交于 2019-12-27 11:35:22
问题 Whatever is inside finally blocks is executed (almost) always, so what's the difference between enclosing code into it or leaving it unclosed? 回答1: The code inside a finally block will get executed regardless of whether or not there is an exception. This comes in very handy when it comes to certain housekeeping functions you need to always run like closing connections. Now, I'm guessing your question is why you should do this: try { doSomething(); } catch { catchSomething(); } finally {

C++, __try and try/catch/finally

£可爱£侵袭症+ 提交于 2019-12-27 11:02:05
问题 I'm wondering a bit about C++ try/catch/finally blocks. I've seen these commands with two underscores like __try. But MVSC 2010 projects also run without the underscores. So when do you need these underscores? 回答1: On Windows, exceptions are supported at the operating system level. Called Structured Exception Handling (SEH), they are the rough equivalent to Unix signals. Compilers that generate code for Windows typically take advantage of this, they use the SEH infrastructure to implement C++

Better to 'try' something and catch the exception or test if it's possible first to avoid an exception?

三世轮回 提交于 2019-12-27 09:54:12
问题 Should I test if something is valid or just try to do it and catch the exception? Is there any solid documentation saying that one way is preferred? Is one way more pythonic ? For example, should I: if len(my_list) >= 4: x = my_list[3] else: x = 'NO_ABC' Or: try: x = my_list[3] except IndexError: x = 'NO_ABC' Some thoughts... PEP 20 says: Errors should never pass silently. Unless explicitly silenced. Should using a try instead of an if be interpreted as an error passing silently? And if so,

Better to 'try' something and catch the exception or test if it's possible first to avoid an exception?

夙愿已清 提交于 2019-12-27 09:53:32
问题 Should I test if something is valid or just try to do it and catch the exception? Is there any solid documentation saying that one way is preferred? Is one way more pythonic ? For example, should I: if len(my_list) >= 4: x = my_list[3] else: x = 'NO_ABC' Or: try: x = my_list[3] except IndexError: x = 'NO_ABC' Some thoughts... PEP 20 says: Errors should never pass silently. Unless explicitly silenced. Should using a try instead of an if be interpreted as an error passing silently? And if so,

Handle Exceptions when using @RequestHeader in spring application

冷暖自知 提交于 2019-12-26 12:23:24
问题 Here is my Java code that uses the Spring Framework: @RequestMapping(method = RequestMethod.POST) public @ResponseBody String SampleFunction(@RequestHeader("Authorization") String details) { System.out.println("Authorization details recieved"); } I am trying to access Authorization header. I want to handle the missing Authorization header by redirecting it to a 400 Bad Request page. How can I do this? 回答1: By default the header is required. So if it is missing, you will get an exception.

Handle Exceptions when using @RequestHeader in spring application

▼魔方 西西 提交于 2019-12-26 12:23:06
问题 Here is my Java code that uses the Spring Framework: @RequestMapping(method = RequestMethod.POST) public @ResponseBody String SampleFunction(@RequestHeader("Authorization") String details) { System.out.println("Authorization details recieved"); } I am trying to access Authorization header. I want to handle the missing Authorization header by redirecting it to a 400 Bad Request page. How can I do this? 回答1: By default the header is required. So if it is missing, you will get an exception.