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
Advertisements
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
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... 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
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 What is the source code for
Sample example for Mortgage Calculator in J2ME language for developing Symbian
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 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:
<...;");
out.println("</html>");
}
}catch (
Exception e
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
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 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
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
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