473,395 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

find the output...

Hi,

I'd just like to ask if anyone would be able to help me find the out put of this peice of code...i took it from a past exam paper,,,,,and i was wondering wat the output maybe...

Expand|Select|Wrap|Line Numbers
  1. public class UsingExceptions {
  2.    // execute application
  3.    public static void main( String args[] )
  4.    {  // call method1 
  5.       try {
  6.          method1();
  7.       }
  8.       // catch Exceptions thrown from method1
  9.       catch ( Exception exception ) {
  10.       System.err.println( exception.getMessage() + "\n" );
  11.          exception.printStackTrace();
  12.       }
  13.    }
  14.    // call method2; throw exceptions back to main
  15.    public static void method1() throws Exception
  16.    {
  17.       method2();
  18.    }
  19.    // call method3; throw exceptions back to method1
  20.    public static void method2() throws Exception
  21.    {
  22.       method3();
  23.    }
  24.    // throw Exception back to method2
  25.    public static void method3() throws Exception
  26.    {
  27.       throw new Exception( "Exception thrown in method3" );
  28.    }
  29. }  // end class Using Exceptions
thanks
Nov 3 '06 #1
3 2436
r035198x
13,262 8TB
Hi,

I'd just like to ask if anyone would be able to help me find the out put of this peice of code...i took it from a past exam paper,,,,,and i was wondering wat the output maybe...

Expand|Select|Wrap|Line Numbers
  1. public class UsingExceptions {
  2. // execute application
  3. public static void main( String args[] )
  4. { // call method1 
  5. try {
  6. method1();
  7. }
  8. // catch Exceptions thrown from method1
  9. catch ( Exception exception ) {
  10. System.err.println( exception.getMessage() + "\n" );
  11. exception.printStackTrace();
  12. }
  13. }
  14. // call method2; throw exceptions back to main
  15. public static void method1() throws Exception
  16. {
  17. method2();
  18. }
  19. // call method3; throw exceptions back to method1
  20. public static void method2() throws Exception
  21. {
  22. method3();
  23. }
  24. // throw Exception back to method2
  25. public static void method3() throws Exception
  26. {
  27. throw new Exception( "Exception thrown in method3" );
  28. }
  29. } // end class Using Exceptions
thanks
Suppose you have a go first and then others can make suggestions.
Nov 4 '06 #2
ok...............i compiled it and i got this:


Exception thrown in method3

java.lang.Exception: Exception thrown in method3
at UsingExceptions.method3(UsingExceptions.java:27)
at UsingExceptions.method2(UsingExceptions.java:22)
at UsingExceptions.method1(UsingExceptions.java:17)
at UsingExceptions.main(UsingExceptions.java:6)

so i just want to know what exactly is the exception.......im not good at readiing them. And im suspecting that if i got this que in my exam i'd only have to say that the output is: Exception thrown in method3
wont I ??

thanks
Nov 4 '06 #3
r035198x
13,262 8TB
ok...............i compiled it and i got this:


Exception thrown in method3

java.lang.Exception: Exception thrown in method3
at UsingExceptions.method3(UsingExceptions.java:27)
at UsingExceptions.method2(UsingExceptions.java:22)
at UsingExceptions.method1(UsingExceptions.java:17)
at UsingExceptions.main(UsingExceptions.java:6)

so i just want to know what exactly is the exception.......im not good at readiing them. And im suspecting that if i got this que in my exam i'd only have to say that the output is: Exception thrown in method3
wont I ??

thanks
When an exception is thrown, e.printStackTrace() is called which traces the paths that led to the exception.
Your solution might or might not be correct depending on whether the stackTrace is being considered part of the program's output or not.
Nov 4 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
4
by: Bill Murray | last post by:
I am using VS.NET 2003 and trying to deploy a service program(c++) to a Windows 2000 Server system. I have also written a small DLL (USSsetup.dll) that is used to start/stop the service using a...
10
by: Sune | last post by:
Hi, previously I used Eclipse CDT for compiling my files just to get started with C and leave C++ behind. Now it's time to get a little more serious so I've moved my files to a new workplace and...
29
by: chellappa | last post by:
hi all I need to write a program to find mac address of a my computer using libaries, is this possible? How? thanks
3
by: rrs.matrix | last post by:
hi is there any system call in unix that will search for a file in the filesystem. someting like the find utility. if not then how should i search for a file in the file system. heard of...
5
by: peter | last post by:
Hello all, I'm looking for an advice. Example (one block in ascii file): $------------------------ NAME='ALFA' CODE='x' $------------------------
3
by: Sharon | last post by:
How can I find what MSXML version I have installed? -- Thanks Sharon
10
by: OppThumb | last post by:
Hi, I've been searching this newsgroup for an answer to my question, and the closest I've come asks my question, but in reverse ("How to figure out the program from plan/package"). I've -- shall...
4
by: lovecreatesbea... | last post by:
The find() in <algorithmrequires two input iterators as its first and second arguments. In some of my code, I use vector<T>::begin() and vector<T>::end() as the first and second arguments. The...
6
by: Robocop | last post by:
I have a simple little script that reads in postscript code, appends it, then writes it to a new postscript file. Everything worked fine a month ago, but after rearranging my directory tree a bit...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.