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

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

    }
}









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
Getting Exception
Getting Exception  How to get exception from commented code in java
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
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...  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  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
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
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
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
Help Me
Help Me  What is the source code for Sample example for Mortgage Calculator in J2ME language for developing Symbian
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  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  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  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  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  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  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  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
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
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
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
pls help me with this question
pls help me with this question  how to write a program in C++ using encapsulation,polymorphism,inheritance and abstraction?(all these concepts should come in a single program
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
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
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
help me - JSP-Servlet
help me   how to open one compiled html file by clicking one button from jsp
program to display frequency count of each word in a file using Hashmap, Hashset and streamtokenizer.plz help me out ..
program to display frequency count of each word in a file using Hashmap, Hashset and streamtokenizer.plz help me out ..  import java.io.*; import...; Program : by HashSet and StringTokenizer import java.io.BufferedReader
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
help me - WebSevices
help me   help me with the principals of designing agood websites and i can start
help me - WebSevices
help me   help me with the principals of designing agood websites and i can start
help me to solve this question
help me to solve this question  Write a program that inputs a series of integers into an array. The numbers are in the range 0 to 100. Calculate and display : a) The Largest number b) The Smallest Number c)The sum of the numbers
Help with this program
Help with this program  Write a program that would do the following: 1) Read a String from the user. The String will be the following: "My grade is x" (where x is an integer between 0-9) 2) Get the String to integer by creating
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
Getting exception in Assocation & Join. - Hibernate
Getting exception in Assocation & Join.  select product0_.id as id0...) exception setting property value with CGLIB (set hibernate.cglib.use_reflection... org.hibernate.PropertyAccessException: exception setting property value with CGLIB
Help with this program
Help with this program  Write a program that would do the following: 1) Read two Strings from the user 2) The user should input two integer numbers. 3) Convert the Strings to integers by creating objects and calling
pls help me it urgent
pls help me it urgent  hey, pls help me i want to know that can we call java/.bat file from plsql/proceudre /trigger
pls help me it urgent
pls help me it urgent  hey, pls help me i want to know that can we call java/.bat file from plsql/proceudre /trigger
pls help me it urgent
pls help me it urgent  hey, pls help me i want to know that can we call java/.bat file from plsql/proceudre /trigger
Help me quickly plz??
Help me quickly plz??  Can you help me to write code quickly this code is a java code take input as double and should use command line arguments and enhanced for statement then find the combine of the numbers plz help quickly

Ads