throws Questions

3

I stumbled upon code looking something like this: void run() { try { doSomething(); } catch (Exception ex) { System.out.println("Error: " + ex); throw ex; } } void doSomething() { throw ne...
Bickel asked 16/10, 2019 at 15:3

9

Solved

class throwseg1 { void show() throws Exception { throw new Exception("my.own.Exception"); } void show2() throws Exception // Why throws is necessary here ? { show(); } void show3() throw...

4

I'm aware checked exceptions have to be handled or specified, but unchecked exceptions are optional. If for some reason I can reasonably expect an unchecked exception to occur in a method, should ...
Univalence asked 1/1, 2014 at 18:23

10

Solved

A method I am calling in run() in a class that implements Runnable) is designed to be throwing an exception. But the Java compiler won't let me do that and suggests that I surround it with try/cat...
Isopropanol asked 20/7, 2012 at 17:25

3

Solved

When attempting to publish the jars for my project via sbt "++2.11.6 publishLocal" or sbt +publishLocal, I encounter Scaladoc issues when publishing for Scala 2.11.6. It appears that I have invalid...
Dishtowel asked 18/7, 2015 at 6:7

2

Solved

I just recently found out that one can use multiple @throws tags for the same exception in Javadoc. One of my students used it to document one of his methods in Connect Four: /* * ... * @throws I...
Herries asked 13/6, 2022 at 6:36

6

Solved

I have a function that throws an error, in this function I have a inside a closure that I need to throw the error from it's completion handler. Is that possible ? Here is my code so far. enum Cal...
Tensimeter asked 19/10, 2015 at 11:53

3

Solved

Not attempting to compare the languages but just for knowledge, Is there any way to have equivalent of java throws keyword/functionality in Python? or the way we can recognize checked exception t...
Albite asked 17/8, 2013 at 13:28

1

In C++20 (N4849), there is no exception safety wording for associative containers' extract() and insert(node_handle)/insert(hint, node_handle) methods. But for merge(), there is this wording though...
Coldhearted asked 10/4, 2021 at 7:7

11

Solved

What is the general rule of thumb when deciding whether to add a throws clause to a method or using a try-catch? From what I've read myself, the throws should be used when the caller has broken th...
Bashemeth asked 8/7, 2010 at 12:1

2

Solved

"Handle or declare. That's the law." - Head First But, is it a good law? Let me give an example first: public static void main(String[] args) throws Exception { m1(); } static void m1...
Tanhya asked 19/10, 2020 at 18:14

10

Solved

In Java, the throws keyword allows for a method to declare that it will not handle an exception on its own, but rather throw it to the calling method. Is there a similar keyword/attribute in C#? ...
Incommutable asked 12/8, 2010 at 7:13

1

In one of my method, interrupted exception and execution exception is coming. I put in try catch like this. try{ //my code }catch(InterruptedException|ExecutionException e) Log.error(" log...

4

Solved

I throw a bunch of custom runtime exceptions in my code and I want to make sure that in all public methods, I document which runtime exception might be thrown (by myself) and why. This would be ver...
Leonaleonanie asked 30/5, 2019 at 13:41

4

Solved

throws keyword is used only for checked exception. It instructs the caller to use try catch block to except all the listed exceptions by throws keyword. Since we know what kind of checked ex...
Leper asked 25/5, 2019 at 9:4

1

When using @dynamicMemberLookup in swift, subscript cannot declare a "throws". subscript(dynamicMember member: String) -> Any This is OK. subscript(dynamicMember member: String) throws ->...
Streamway asked 15/11, 2018 at 17:53

4

Solved

So I have two general questions about java in general. The first is when would one use a try/catch in the body of the method versus using throws exception in declaring the method? Here is a l...
Glasgow asked 4/7, 2015 at 1:24

2

Solved

I am using an SQLite library in which queries return optional values as well as can throw errors. I would like to conditionally unwrap the value, or receive nil if it returns an error. I'm not tota...
Farant asked 25/9, 2016 at 19:52

6

Solved

I've never used the "throws" clause, and today a mate told me that I had to specify in the method declaration which exceptions the method may throw. However, I've been using exceptions without prob...
Christopherchristopherso asked 3/2, 2011 at 17:50

1

Solved

This code is not compiling on Swift 3.3. It's showing the message: 'self' used inside 'catch' block reachable from super.init call public class MyRegex : NSRegularExpression { public init(patter...
Sunshade asked 26/4, 2018 at 14:37

8

Solved

Can any of you explain what the differences are between throw, throws and Throwable and when to use which?
Tyro asked 15/10, 2010 at 7:18

7

Solved

So I thought I had a good basic understanding of exception-handling in Java, but I was recently reading some code that gave me some confusion and doubts. My main doubt that I want to address here i...
Deandreadeane asked 8/12, 2010 at 21:18

2

Solved

I have defined a function in Kotlin: fun convertExceptionToEmpty(requestFunc: () -> List<Widget>): Stream<Widget> { try { return requestFunc().stream() } catch (th: Throwable) { ...
Omniscience asked 24/8, 2017 at 14:42

2

Solved

After searching for some references to figure it out, -unfortunately- I could not find useful -and simple- description about understanding the differences between throws and rethrows. It is kind of...
Faeroese asked 9/4, 2017 at 9:16

3

Solved

I'm writing a program in Java, and nearly every method in one of my classes is written like: public void doStuff() throws AWTException{} Is there a way for me to get rid of the extra step of typ...
Gorton asked 10/12, 2010 at 5:25

© 2022 - 2024 — McMap. All rights reserved.