Questions tagged [rethrow]

use for issues on rethrowing catch exception

In terms of exception handling, this refers to throwing the exception again.

73 questions
2
votes
5 answers

Need of Java's "more precise rethrow in exceptions"

I am having trouble understanding how precise rethrow works in Java 7 and later versions. As pointed out in https://www.theserverside.com/tutorial/OCPJP-Use-more-precise-rethrow-in-exceptions-Objective-Java-7, in Java 7 and later versions we can…
gambarimas87
  • 51
  • 2
  • 6
2
votes
1 answer

How to declare a rethrowing function?

I implemented the following function -as an extension of array of booleans- which could throw a CustomError error: enum CustomError: Error { case empty case doesNotContainTrue } extension Array where Element == Bool { func…
Ahmad F
  • 30,560
  • 17
  • 97
  • 143
2
votes
1 answer

Does catch-all-rethrow differ in any way from having no try-catch block at all?

Does this code try { opaque_function_that_might_throw_arbitrary_exception (); } catch (...) { throw; } differ in any way semantically from just calling opaque_function_that_might_throw_arbitrary_exception (); in C++? Are there differences…
levzettelin
  • 2,600
  • 19
  • 32
2
votes
3 answers

Powershell try/catch rethrow not propagating error (Powershell 2.0)

I have a try-catch statement within a try-catch statement. The inner catch catches the error, but the throw does not cause the error to be caught in the out catch statement. Breifly, my script is formatted similar to: $ErrorPreference =…
user459866
  • 121
  • 3
  • 12
2
votes
0 answers

Stackoverflow while rethrowing exception due to ntdll!RcConsolidateFrame (x64)

I am struggling with a stack overflow exception, which occurrs while rethrowing a different exception. The rethrown exception is used to tear down the callstack after a recursive function has called itself more than a certaing number of times. (To…
whY
  • 189
  • 1
  • 10
2
votes
1 answer

Tell F# that reraise returns no value

How do I help the F# compiler interpret re-throwing an exception as having no return value? For example, consider wrapping an operation to log the exception: let doDivision() = try 2 / 0 with ex -> log ex reraise The…
Edward Brey
  • 40,302
  • 20
  • 199
  • 253
2
votes
2 answers

Can I still rethrow an exception from within a function called within a catch block?

I have the following structure in the legacy codebase: try{ ... } catch(Type1&){ ... } catch(Type2&){ ... } ... And with copy-paste development, the same catch blocks show up everywhere. Now, I would write a function like this: void catchErrors(){ …
Barney Szabolcs
  • 11,846
  • 12
  • 66
  • 91
2
votes
1 answer

Throwing exception after modifying its Dictionary

The following is my code in C#: catch(Exception ex) { ex.Data.Add("VarName", "object"); throw; } Question: doing above, am I going to lose the entry I am adding to Data dictionary? -->as in my opinion, I am rethrowing the exception caught in…
coder0h1t
  • 443
  • 5
  • 9
1
vote
3 answers

What happens when we throw an object/variable to catch?

Two Questions 1) What happens when an Object/variable is thrown to catch? Say for example, int foo() { FILE *fp = ....; int dummy = 10; int *dummy_ptr = new int[10]; throw 1; } int main() { try { foo(); } catch (int &i) { …
howtechstuffworks
  • 1,824
  • 4
  • 29
  • 46
1
vote
1 answer

Dart: try catch not catching the exception from a function that uses 'rethrow'

I'm trying to use the library livekit_client to create a chat room, I'm trying to handle the exception when the connection fails, this is the code I'm using to connect and catch the error: try { room.connect( 'ws://localhost:7880', …
MOHAMMAD RASIM
  • 335
  • 1
  • 6
  • 14
1
vote
1 answer

Python equivalent of MATLAB's rethrow()

I'm trying to port a working MATLAB code in Python. I am trying to create the var array with size (rows, cols). If an exception is raised, I catch it and try again to create the var array with size (rows, cols-1). If cols gets to zero, then I cannot…
Java Jaard
  • 33
  • 7
1
vote
0 answers

Rethrow original exception when catch clause has another try-catch which throws nothing - equivalent in Reactive pipeline

I have a method which would be like this in traditional, imperative try-catch coding style: void confirmCart(Checkout Order) { try { cartService.confirm(order.getCartId(), order.getCartHash()); } catch (Exception ex1) { …
WesternGun
  • 11,303
  • 6
  • 88
  • 157
1
vote
0 answers

init(_:uniquingKeysWith:) : Call can throw, but it is not marked with 'try' and the error is not handled

I have a doubt with rethrows. Following code is inside Dictionary extension: init(_value: [(Key, Value)]) { self.init(_value, uniquingKeysWith: { _, first in first }) //Call can throw, but it is not marked with 'try' and the error is…
SwiftUser
  • 29
  • 8
1
vote
0 answers

Why does javax.tools.ToolProvider.getSystemTool(...) rethrow with the widest Error class instead of ServiceConfigurationError?

The method javax.tools.ToolProvider.getSystemTool(Class clazz, String moduleName, String className) has the following body (JDK 12): private static T getSystemTool(Class clazz, String moduleName, String className) { try { …
1
vote
0 answers

C#. Strange behavior when re-throwing exception

While exception log investigation I've faced a strange behavior for exception callstack when using throw; for re-throwing catched exception. For example string callstack1, callstack2; try { try { // some code throwing exception …
Andre D
  • 19
  • 2