Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Getting Exception on UseDefinedException sample program - Please help me how to resolve
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


durga kishore
Getting Exception on UseDefinedException sample program - Please help me how to resolve
1 Answer(s)      2 years and 5 months ago
Posted in : Java Beginners


class UseDefinedException extends Exception{
   String msg = "";
  int marks;
   public UseDefinedException() ){
 }
   public UseDefinedException(String str){
   super(str);
 }
  public String toString(){
   if marks <= 50)
   msg = "You have failed";  

  if marks > 50) 

   msg = "You have Passed"; 
   return msg;
}
}
  public class test{
  public static void main(String args[]){
  test t = new test();
   t.mm();
}
  public void mm(){
  try{
   int i=0;

  if( i < 50) 
  throw new MyException();

}
   catch(MyException ee1){
  System.out.println("my ex"+ee1);
}
}
}

Hi,

I tried above code but getting Exception : MyException cannot be resolved to a type

at Interface.test1.me(test1.java:41)
at Interface.test1.main(test1.java:34)

what is MyException and how it called ..please explain ..?


Advertisement
View Answers

September 3, 2012 at 6:06 PM


MyException should be a class name that defined custom exception. Here is an example of user-defiend exception.

class MyException extends Exception 
{ 
    public MyException(String message)         
    {  
        super(message);        
    }      
}

class CustomException{
   public static void main(String args[]) throws Exception    
    {          
         for(int i=1;i<=5;i++)       
        {              
            System.out.println("i= "+i);           
            if(i==3)           
            {                  
              throw new MyException("My Exception Occurred");              
            }          
        }        

    }
}


Related Tutorials/Questions & Answers:
Can anybody tell me how to resolve this issue?
Can anybody tell me how to resolve this issue?  java.lang.Exception: Exception : java.lang.Exception: Generic Errors = java.util.MissingResourceException: Can't find bundle for base name Connection, locale en_US
my hibernate showing the following exception so how i can resolve it
my hibernate showing the following exception so how i can resolve it   Caused by: java.lang.ClassNotFoundException: org.hibernate.Session...: TestClient. Program will exit
Advertisements
Getting Exception
Getting Exception  How to get exception from commented code in java
plz help me find a program
plz help me find a program  plz help..i want a source code in jsp for order processing
how to resolve this JDBC Error?
how to resolve this JDBC Error?  i am trying to Exceute this code: import java.sql.DatabaseMetaData; import java.sql.Connection; import... but when i am executing this code i am getting this Error: Exception in thread
How to resolve NumberFormatException(Unlnown Source)?
How to resolve NumberFormatException(Unlnown Source)?  I'm using some code where I'm getting NumberFormatException in the code but logically it seem to me perfectly ok because whenever I 'm using that code in .java file it works
MYSQL EXCEPTION -DATA TRUNCATION..pls resolve it
MYSQL EXCEPTION -DATA TRUNCATION..pls resolve it  while running my program as follows Register1.html <!DOCTYPE html> <html lang="en... Validation using a sample registration form</title> <meta name
Help me to write this simple java frame program
Help me to write this simple java frame program   I want to write a Java program for.... To create a frame with 4 text fields;name,street,city and pin;with suitable labels. Also add a button "OK". After enter values
MYSQL EXCEPTION -DATA TRUNCATION..pls resolve it
MYSQL EXCEPTION -DATA TRUNCATION..pls resolve it  while running my program as follows Register1.html <!DOCTYPE html> <html lang="en...; while running this program in tomcat server i got the following exception
Sample java program
Sample java program  I want a sample program: to produce summary information on sales report. The program will input Data of Salesman Id, Item code, and number of cuestomer. Sales id is 5digit long, and items code range from
Help Me
Help Me  What is the source code for Sample example for Mortgage Calculator in J2ME language for developing Symbian
I am getting this exception
I am getting this exception   Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java
Getting an exception - JSP-Servlet
Getting an exception  sir i m Getting an following exception while... sending message; nested exception is: java.io.FileNotFoundException...); }catch(Exception e){ System.out.println("Send Mail exception
it is a linux program is there anyone who can help me out with it?
it is a linux program is there anyone who can help me out with it?  Write a Bash script that prompts the user for a user-ID and displays the corresponding user√Ę‚?¨‚?Ęs login name, owner√Ę‚?¨‚?Ęs name, and his/her home directory
help me
help me... the flow of people , cars , airplanes , transactions , and so on . write a program... by pressing a key. you will need to determine how the customer will decide which line
help me..
help me..  Write a program that inputs four words and them displays all possible permutations of the words. So, for example, if the words mad, dog, bites and man are entered, then the following are output : man bites mad dog mad
help me...
help me...  Write a program that inputs four words and them displays all possible permutations of the words. So, for example, if the words mad, dog, bites and man are entered, then the following are output : man bites mad dog
Sample program of JSP
Sample program of JSP  <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org
error occured in following page ... how to resolve it?
error occured in following page ... how to resolve it?  // to convert image into thumbnail i used following code. But netbeans has given me following....... error is:::: Exception in thread "main" java.lang.IllegalArgumentException
help me
help me  i have done as u directed but nothing happens gud to me..... . i am using netbeans is that matter at all help me and take me out from trouble where to store jfree api to use it for j2ee based project
How to resolve this error The filename, directory name, or volume label syntax is incorrect
How to resolve this error The filename, directory name, or volume label syntax... + createTimeStampStr() + ".PNG"; this my program public class Image...() throws Exception { ................... } public void randomImage(String
Sample program of JSP
Input program in JSP  <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org
help me..
help me..  Design and write a class named Person and its two subclasses named Student and Employee. Make Lecturer and Admin subclasses of Employee... constructor for each class. Draw the UML diagram for the classes. Write a test program
help me
help me  how to print from a-z, A-Z with exact order using for loop? Thanks for all concern
Help me
Help me  plz i want code of program to add real numbers and magic numbers in java example this input :- 5+3i-2+3i output:- 3+6i
help me..
help me..   what are the component needed by grid computing, cloud computing and ubiquitous computing? discuss about the security of above computing. difference between that 3 computing
very urgent : Iam unable to code this program plz help me - RMI
very urgent : Iam unable to code this program plz help me  Write a Multi-user chat server and client.  Hi friend, Chat server is a standlone application that is made up the combination of two-application, server
Pleae help me to give logic and code for this program - Java Beginners
Pleae help me to give logic and code for this program  Write a function that given the string ?original? create a new string ?dramatic? that has two consecutive copies of each letter from the original string. For example
help me...
help me...  there is the picture given - cat - dog - rabbit - mouse a. create a class name b. create its attributes (at least 3 attributes) : species, size, leg c. create its methods ( at least 3 methods) : walk, eat, sleep
Help me
Help me  hello!!!!. i have a Excel file which includes 4 columns and somewhat 8500 rows.these rows i have printed in SQL thru Excel file and i have... out from java output so how to do all dis
help me
help me  Create a GUI application that allows a user to select a text file (using the JFileChooser). The program will then allow the user to do... program should list all the line number where the word is found. To do
Advertisements
 

 

 

DMCA.com