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

 
 


durga kishore
Getting Exception on UseDefinedException sample program - Please help me how to resolve
1 Answer(s)      8 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 ..?

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 Pages:
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
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
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 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
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
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
Getting Exception
Getting Exception  How to get exception from commented code in java
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
Exception
help me.   public class FooException extends Exception { public...Exception  public class FooException extends Exception { public..."); } public void calculate() throws FooException, Exception { try { int
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
sql exception - JSP-Servlet
sql exception  Dear sir , I am working in a web-based project, In my system it is working fine but at client side getting the following exception so how to resolve this help me... java.sql.SQLException: ORA-28231
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
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
help me 2
help me 2  write java program to enter five numbers and will determine the location of the number sample output: ENTER 5 NUMBERS: 1 2 3 4 5 ENTER NUMBER TO SEARCH:1{press enter} 1 found in index 0   import
Help Me
Help Me  What is the source code for Sample example for Mortgage Calculator in J2ME language for developing Symbian
exception - MobileApplications
exception  Hi friend, again i am getting exception.Entire code of my program i am sending.Plz suggest me. import javax.microedition.midlet....:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Winter.jpeg
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  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..  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  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...;/html>"); } }catch (Exception e) { e.printStackTrace...;"); out.println("</html>"); } }catch (Exception e
Help me
Help me  HI I am using Tomcat6.0 this is the problem i got wen i run the code , i am using login.html ,login .jsp,login.java and web.xml code...;/html>"); } }catch (Exception e) { e.printStackTrace
bean creation exception
bean creation exception  hi i am getting exception while running simple spring ioc program Exception in thread "main... to resolve the above exception   The server is trying to load this file
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 use Bean Area in Oracle Forms 9i with Sample code ?
How to use Bean Area in Oracle Forms 9i with Sample code ?  Hi friend.I posted a query,but I didn't get the answer for it.Help me to resolve including a bean area in oracle forms 9i and using it in forms.Thanks in advance.Help me
help
running it, it tells me:- Exception in thread "main... fine and gives the correct answer. my question is why wont it compile and, how
Exception Handling-Error Messages in Program
Exception Handling-Error Messages in Program  Hi Friend, I am having trouble running this code as per my prior question on Exception handling of yesterday.I may be putting into the wrong files, I'm not sure, but could you help me
HQL Sample
HQL Sample In this site there are many tutorials and example of HQL. These examples comes with HQL sample code that you can download and run on your computer and learn the HQL by modifying and executing these examples. The HQL Sample
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
getting coords from an image.
getting coords from an image.  how to get coordinates dynamically(in run time) from an image?? pls help me
exception - Struts
in struts I am getting the exception javax.servlet.jsp.JspException: Cannot...: Exception in JSP: /FileUpload.jsp:10 7: 8: 9: 10: 11: 12: 13: can anybody help me regards, Sorna   Hi friend, Here
pls help me sir its urgent
pls help me sir its urgent  thanks for reply, but i am getting this error pls help me its urgent type Exception report message... fulfilling this request. exception javax.servlet.ServletException
java runtime exception - JDBC
"); } catch (Exception e) { e.printStackTrace(); } } } i got an exception that classnotfoundexception . how can i remove this exception. i am executing my prgm on command prompt in window 7
help me - JSP-Servlet
help me   how to open one compiled html file by clicking one button from jsp
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 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
what are the jar files should i add to resolve the Exception(Class org.apache.jsp.index_jsp Not Found) ?
what are the jar files should i add to resolve the Exception(Class... to resolve the following Exception HTTP Status 500 - type Exception report... it from fulfilling this request. exception javax.servlet.ServletException: Wrapper
Need sample code
Need sample code  Need code for graph which shows the performance comparission of aprior algorithm and coherent rule algorithm.plz can any one help me i need in a week
Exception handling
Exception handling  how to resolve file not found error exception
User Defined Exception
.     How to Handle and create User-defined Exception The keywords used... the description of the exception in program Throwable..., the UseDefinedException,subclass of  the Exception class is created
User Defined Exception
.     How to Handle and create User-defined Exception The keywords used... the description of the exception in program Throwable..., the UseDefinedException,subclass of  the Exception class is created
help me to solve this question...
help me to solve this question...  Given below is a class definition for Book. Type and compile the class, and answer the following questions... price; } } Write a program in a class TestBook that can do the following: Read
help me to solve this problem..
help me to solve this problem..  Given below is a class definition for Book. Type and compile the class, and answer the following questions: class...; } } Write a program in a class TestBook that can do the following: Read
plz Help me find the correct programs answers
plz Help me find the correct programs answers   Create a washing... and loading capacity. Display the updated truck details. Write a program which... to the program so as to accept any type of numeric values and returns the results
HELP ME - Java Beginners
HELP ME  How can I write only digits in the the textfield when I am using keyTyped and keyPressed metods of KeyListener, but I do not want to write an any character in it?(This question means when a user pressed a key in keyboard
pleasa help me?
pleasa help me?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access... named TestCircle to test the Circle program by creating two Circle objects

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.