Answers for "throw an exception"

38

throw new error(

throw new Error('Whoops!')
Posted by: Guest on March-17-2020
2

throw new error(

throw new Exception("Error here");
Posted by: Guest on August-08-2021
1

throw new error(

try {
  throw "I'm Evil"
  console.log("You'll never reach to me", 123465)
} catch (e) {
  console.log(e); // I'm Evil
}
Posted by: Guest on August-05-2021
2

java throw an exception

public static void main(String[] args) {
	Scanner kb = new Scanner(System.in);
    System.out.println("Enter a number");
    try {
    	double nb1 = kb.nextDouble();
    	if(nb1<0)
        	throw new ArithmeticException();
        else System.out.println( "result : " + Math.sqrt(nb1) );
    } catch (ArithmeticException e) {
        System.out.println("You tried an impossible sqrt");
    }
}
Posted by: Guest on October-16-2020
2

throwing exceptions java

/* In this program we are checking the Student age
 * if the student age<12 and weight <40 then our program 
 * should return that the student is not eligible for registration.
 */
public class ThrowExample {
   static void checkEligibilty(int stuage, int stuweight){ 
      if(stuage<12 && stuweight<40) {
         throw new ArithmeticException("Student is not eligible for registration"); 
      }
      else {
         System.out.println("Student Entry is Valid!!"); 
      }
   } 

   public static void main(String args[]){ 
     System.out.println("Welcome to the Registration process!!");
     checkEligibilty(10, 39); 
     System.out.println("Have a nice day.."); 
 } 
}
Posted by: Guest on May-08-2020
0

throw new error()

/*
	throw new Error("error"); is a javascript line made up of two elements which
    are used to gether at most of the times in making of javascript libraries,
    for people to use to make an action easier than normal, to give errors when
    the people gave a spelling error or syntax error, as they gave a string
    instead of a number, etc.
*/

// Is't usage is:
throw new Error("error");

/*
	Like I said, throw new Error("error") has two elements, the first element
    is throw and the second element is new Error("error")
    
    throw is used to throw something in the console box, here it is used to
    throw an error
    
    new Error("error") is used to create a new Error object which has the
    argument as "error", the argument is the error which should be shown in the
    console, Error is an object which is predefined in javascript using a
    constructor, you cannot change its definition using another constructor
    named as Error
    
    Most of the times, they both are used in pairs directly, in some rare, they
    are used in pairs indirectly i.e. storing the error object in a variable and
    throwing it in the console using throw
    
    This case might happen very rare when you need to call the error using two
    different loal variables which are in different functions, then you may do
    this:
*/
var error;

function function1() {
  let variable1 = "hello";
  error = new Error("Error: " + variable1);
  // error is now Error: hello
}

function function2() {
  let varible2 = "world";
  error = new Error(error + " " + variable2);
  // and now the error is Error: hello world
}
Posted by: Guest on September-03-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language