Getting Exception on UseDefinedException sample program - Please help me how to resolve

Ads
 

Getting Exception on UseDefinedException sample program - Please help me how to resolve

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 ..?

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");              
            }          
        }        

    }
}

Ads









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
plz help me find a program
plz help me find a program  plz help..i want a source code in jsp for order processing
Advertisements
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
How do I resolve this Java Class not found exception?
How do I resolve this Java Class not found exception?  Hi, Many time new developer faces the Class not found exception. Why it happens and how to resolve this? Thanks   Hi, The main reason of this exception is un
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
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
Getting exception in hello world
Getting exception in hello world  I run your hibernate5 "hello world" program. But, getting an exception: ERROR: Table 'mydb.employee' doesn't exist Exception in thread "main" javax.persistence.PersistenceException
Getting exception in hello world
Getting exception in hello world  I run your hibernate5 "hello world" program. But, getting an exception: ERROR: Table 'mydb.employee' doesn't exist Exception in thread "main" javax.persistence.PersistenceException
Help Me
Help Me  What is the source code for Sample example for Mortgage Calculator in J2ME language for developing Symbian
How to create the program in Java for getting the forgotten Password Form?
How to create the program in Java for getting the forgotten Password Form?  Hi, Our enterprise application requires the development of a form... to the user on email address. How to create the program in Java for getting
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
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
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
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... 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..   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
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...  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  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  Hi, LWUIT is working in eclipse j2me for Symbian OS
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  HI I am using Tomcat6.0 this is the problem i got wen i run... (Exception e) { e.printStackTrace(); } } } Does anyone have...;/html>"); } }catch (Exception e) { e.printStackTrace
help me
help me  pls... xplain dis code:- function go() { window.location.replace("logout.jsp",'window','toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1'); self.close
Help me
Help me  HI I am using Tomcat6.0 this is the problem i got wen i run... (Exception e) { e.printStackTrace(); } } } // html file is: &lt...;"); out.println("</html>"); } }catch (Exception e
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
help me
help me  I have a quastion a bout array whic is>>> 1-write aprogram to diplay a multiplication table for 1to 10 by entering the start number and the end number. EXAMPLE: ENTER START NUMBER:1 ENTER END NUMBER:3
plzzz help me!!
plzzz help me!!  . Write a program to display a multiplication table, by entering the start number and the end number. Sample output: Enter start number: 1 Enter end number: 2 {press enter} 1 2 3 4 5 6 7 8 9 10 1
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
getting classnotfound exception while running login application
getting classnotfound exception while running login application  hi, I am getting Error creating bean with name 'urlMapping' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference
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

Ads