exception-handling

Better handling of number format exception in android

 ̄綄美尐妖づ 提交于 2021-02-10 13:26:10
问题 I've got the following code snippet that I'm thinking of refactoring to a more abstract application exception handler but I want to make sure I've got it as tidy as possible first Any suggestions on how to improve this code or make it more resuable int id = -1; final StringBuilder errorMessage = new StringBuilder("Bad Input Value: "); try { id = Integer.parseInt(edtId.getText().toString()); } catch (final NumberFormatException e) { errorMessage.append("Failed to parse id " + e.getMessage());

RAII Failure - Why Does this C++ Code Leak? - throw in ctor in try block prevents dtor

不想你离开。 提交于 2021-02-10 13:10:37
问题 The output of the program below is: begin try Object() ctor begin catch Why is the Holder class's destructor not called? Is this a memory leak? Is it possible to call the Holder class's destructor without rethrowing? #include <iostream> #include <exception> class Object { public: Object() { std::cout << "Object() ctor" << std::endl; } ~Object() { std::cout << "~Object() dtor" << std::endl; } }; class Holder { public: Holder() :myObjectP( new Object() ) { throw std::exception(); } ~Holder() {

Received “UnboundLocalError: local variable 'e' referenced before assignment” when the variable was initialized

早过忘川 提交于 2021-02-08 20:52:50
问题 [Community edit to give reproducible example:] def main(): e = None print(locals()) while not e: try: raise Exception except Exception as e: pass main() produces ~/coding$ python3.3 quiz2.py {'e': None} Traceback (most recent call last): File "quiz2.py", line 11, in <module> main() File "quiz2.py", line 5, in main while not e: UnboundLocalError: local variable 'e' referenced before assignment [EDITED] to include a reproducible code I am trying to run a while-loop, and the condition I use is

Why does C++ allow to throw anything?

[亡魂溺海] 提交于 2021-02-08 19:42:43
问题 I just saw this question and its related answers. Considering I never ran into this way of using throw s before, I was quite surprised to find out this is even possible. What's the logic behind allowing (almost) anything to be thrown and caught? Is there a use of the throw-catch syntax that goes beyond exception/error signaling? And if so, is that considered bad practice or are there "common" usages of this I was never aware of? 回答1: This is hard to answer without speculation, but Bjarne's

Why does C++ allow to throw anything?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-08 19:42:06
问题 I just saw this question and its related answers. Considering I never ran into this way of using throw s before, I was quite surprised to find out this is even possible. What's the logic behind allowing (almost) anything to be thrown and caught? Is there a use of the throw-catch syntax that goes beyond exception/error signaling? And if so, is that considered bad practice or are there "common" usages of this I was never aware of? 回答1: This is hard to answer without speculation, but Bjarne's

Catching & Handling Jackson Exceptions with a custom message

♀尐吖头ヾ 提交于 2021-02-08 12:19:57
问题 I'm hoping to to catch some jackson exceptions that are occurring in a spring-boot API I am developing. For example, I have the following request class and I want to catch the error that occurs when the "questionnaireResponse" key in the JSON request object is null or blank i.e " " in the request object. @Validated @JsonRootName("questionnaireResponse") public class QuestionnaireResponse { @JsonProperty("identifier") @Valid private Identifier identifier = null; @JsonProperty("basedOn") @Valid

PHP exception not being caught, laravel, lumen

荒凉一梦 提交于 2021-02-08 07:59:58
问题 When attempting to catch/handle an exception thrown from PDFParser, I cannot catch it. I use a simple try catch statement, outlined below. try{ $pdf = $parser->parseFile($filepath); $text = $pdf->getText(); } catch( \Exception $e){ $text = $paper->abstract; } The exception is thrown as follows. if (empty($data)) { throw new \Exception('Object list not found. Possible secured file.'); } The output is here. lumen.ERROR: Exception: Object list not found. Possible secured file. in /Users

PHP exception not being caught, laravel, lumen

我们两清 提交于 2021-02-08 07:58:52
问题 When attempting to catch/handle an exception thrown from PDFParser, I cannot catch it. I use a simple try catch statement, outlined below. try{ $pdf = $parser->parseFile($filepath); $text = $pdf->getText(); } catch( \Exception $e){ $text = $paper->abstract; } The exception is thrown as follows. if (empty($data)) { throw new \Exception('Object list not found. Possible secured file.'); } The output is here. lumen.ERROR: Exception: Object list not found. Possible secured file. in /Users

PHP exception not being caught, laravel, lumen

限于喜欢 提交于 2021-02-08 07:58:41
问题 When attempting to catch/handle an exception thrown from PDFParser, I cannot catch it. I use a simple try catch statement, outlined below. try{ $pdf = $parser->parseFile($filepath); $text = $pdf->getText(); } catch( \Exception $e){ $text = $paper->abstract; } The exception is thrown as follows. if (empty($data)) { throw new \Exception('Object list not found. Possible secured file.'); } The output is here. lumen.ERROR: Exception: Object list not found. Possible secured file. in /Users

There is no row at position 0

自古美人都是妖i 提交于 2021-02-07 20:22:03
问题 cmd.CommandText = "select * from product where prod_code='" & Trim(txtprod_code.Text) & "' and branch='" & w_location & "' and avail_stock <>" & (0) & "" cmd.CommandType = CommandType.Text con.Open() da_uqc.SelectCommand = cmd cmd.Connection = con da_uqc.Fill(ds_uqc) m_qty = ds_uqc.Tables(0).Rows(0)(4) 'error da_uqc.Dispose() ds_uqc.Dispose() cmd.Dispose() Is it possible to give like this m_qty = ds_uqc.Tables(0).Rows(0)(4) ? 回答1: You're getting a run-time error denoting that there was no