About 303,000 results
Open links in new tab
  1. How to define custom exception class in Java, the easiest way?

    Sep 23, 2010 · I'm trying to define my own exception class the easiest way, and this is what I'm getting: public class MyException extends Exception {} public class Foo { public bar() throws …

  2. How to create a custom exception type in Java? [duplicate]

    There is 1) creating a custom exception type/class (as shown so many times) and 2) raising the exception. To raise an exception, simply pass the appropriate instance to throw, normally: …

  3. How can I throw a general exception in Java? - Stack Overflow

    In C#, you do not have to derive a new class from Exception. You may simply "throw new Exception (message);" for example, and handle it generically in the block that will catch the …

  4. java - Cannot be cast to class - they are in unnamed module of …

    In my case it was a little bit different. Class Cast Exception sometime happen because of the conflict between different version of the java. in pom.xml i set to use …

  5. java - How do you assert that a certain exception is thrown in JUnit ...

    How about this: catch a very general exception, make sure it makes it out of the catch block, then assert that the class of the exception is what you expect it to be.

  6. java - Get exception instance class name - Stack Overflow

    Sep 11, 2015 · The benefit of the multi-catch is that you can handle multiple exception types within a single catch block without having to revert to a common super class (like …

  7. How and where do you define your own Exception hierarchy in Java?

    36 How and where do you define your own Exception hierarchy in Java? My main question concerns package location where your Exception classes must be defined. Do we create a …

  8. java - How to assert an exception is thrown with JUnit 5 ... - Stack ...

    174 In Java 8 and JUnit 5 (Jupiter) we can assert for exceptions as follows. Using org.junit.jupiter.api.Assertions.assertThrows public static < T extends Throwable > T …

  9. Explanation of ClassCastException in Java - Stack Overflow

    May 25, 2009 · A class cast exception is thrown by Java when you try to cast an Object of one data type to another. Java allows us to cast variables of one type to another as long as the …

  10. Difference between java.lang.RuntimeException and …

    Feb 3, 2010 · Someone please explain the difference between java.lang.RuntimeException and java.lang.Exception? How do I decide which one to extend if I create my own exception?