Questions tagged [checked-exceptions]

The exceptions that need to be declared in a method or constructor's `throws` clause if they can be thrown by the execution of the method or constructor and propagate outside the method or constructor boundary.

The class Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch.

The class Exception and any subclasses that are not also subclasses of RuntimeException are checked exceptions. Checked exceptions need to be declared in a method or constructor's throws clause if they can be thrown by the execution of the method or constructor and propagate outside the method or constructor boundary.

Details: http://docs.oracle.com/javase/7/docs/api/java/lang/Exception.html

145 questions
5
votes
2 answers

How does JVM handles RuntimeException(s)

While creating custom exceptions, If we want to create a checked Exception we extend the Exception class and for unchecked exception we extend the RuntimeException class. My question is, how JVM handles subClasses of RuntimeException and Exception…
gaurs
  • 575
  • 1
  • 5
  • 19
4
votes
6 answers

relax exception catch necessity

Is there a possibility in Java to get rid of the necessity to catch non-RuntimeException exceptions? Maybe compiler flags? I know the reason why the catching is promoted, but want to do simple and straight tools that enforce their requirements. So…
dronus
  • 10,774
  • 8
  • 54
  • 80
4
votes
2 answers

IntelliJ: Search for Checked exceptions, declared in method signature, but never thrown in body

I've got a rather simple IntelliJ/tool question here: I'm currently dealing with some legacy code and started to rework stuff here and there. What I stumbled upon very often are declared (checked) exceptions in the method signature, although these…
4
votes
3 answers

Java compile time checked exception

Exception and IOException both are compile time checked exceptions. But, we cant use IOException within catch block. But we can use Exception within catch block what is the reason for it. import java.io.*; class Demo{ public static…
Saveendra Ekanayake
  • 3,153
  • 6
  • 34
  • 44
4
votes
2 answers

Managing checked exceptions in different JUnit tests

I am writing a Java Unit test for one of my method. The method declaration is like this: public int convertToInteger() throws InvalidRomanNumberException { int result=0; BaseRomanNumeral num1, num2; int i=0; if(!validOperation()) …
gazubi
  • 561
  • 8
  • 32
4
votes
2 answers

Can a terminal operation (e.g. forEach) rethrow checked exceptions?

I have a method that deletes some files: void deepDelete(Path root) { Files.walk(root) .filter(p -> !Files.isDirectory(p)) .forEach(p -> { try { Files.delete(p); } catch (IOException e) { /*…
assylias
  • 321,522
  • 82
  • 660
  • 783
4
votes
1 answer

Where to put the throws clause in a property declaration?

The compiler complains about this code: public OdbcVersion odbc_version { set { set_odbc_version_ (value); } } private void set_odbc_version_ (OdbcVersion value) throws UnixOdbcError { if (!succeeded (set_environment_attribute_real (handle,…
Jens Mühlenhoff
  • 14,565
  • 6
  • 56
  • 113
4
votes
1 answer

HttpWebRequest proper exception handling

So I'm using the HttpWebRequest API in the System.Net assembly but because C# has no checked exceptions, I'm not sure where to put my try-catch blocks to properly handle inevitable exceptions caused by common things like a network error. You know,…
AxiomaticNexus
  • 6,190
  • 3
  • 41
  • 61
4
votes
1 answer

What is a good practice of dealing with some runtime HTTP exceptions?

I have a small method that looks like this: public static void unstarTrack(Context ctxContext, String strId) { try { HttpParams htpParameters = new BasicHttpParams(); List lstCredentials = new…
Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382
3
votes
2 answers

Can I set eclipse to show a warning if RuntimeException is not handled?

I have the following code: public static void main(String[] args) { willItThrowException(); } private static void willItThrowException() throws RuntimeException { throw new RuntimeException(); } Is there any configuration of eclipse that…
oshai
  • 14,865
  • 26
  • 84
  • 140
3
votes
6 answers

Throw checked exceptions

A few of my methods in Java throw exceptions such as NoSuchElementException, IllegalArgumentException, etc. But when using these methods, these exceptions appear to be unchecked. In other words, caller of my methods is not required to do a try/catch…
Carven
  • 14,988
  • 29
  • 118
  • 161
3
votes
2 answers

How can I collect results of a Java stream operation that throws exceptions in a concise manner?

Have a look at the following snippet that tries to convert a list of strings into a list of class objects: public static List> f1(String... strings) { return Stream.of(strings) .map(s -> { try { …
Angle.Bracket
  • 1,438
  • 13
  • 29
3
votes
1 answer

How to specify the exceptions raised by a Delphi method?

Again a Delphi newbie question. Is there a standard way of specifying the exceptions raised by a method (I have googled this but can't seem to find anything on the topic beyond the basics of handling exceptions). In other words is there a standard…
BigONotation
  • 4,406
  • 5
  • 43
  • 72
3
votes
2 answers

Automatically adding/removing checked exceptions while prototyping

I would rather not add/remove throws clauses manually, especially while prototyping. Is there a batch refactoring tool that adds/removes throws clauses to every method to reflect the code? After all, the compiler tells you what exceptions a method…
Eleno
  • 2,864
  • 3
  • 33
  • 39
3
votes
7 answers

Types of Exception in Java

I am confused about types of exceptions in Java. On many tutorial websites I have seen that two types of exception are there in java Compile time exception Run time exception But when I talked with some java masters, according to them there is no…
inj3ct0r
  • 197
  • 1
  • 3
  • 13