473,382 Members | 1,545 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,382 software developers and data experts.

Catch/Throw

I was wondering... you know how java has the ability for us to create a catch throw method for catching and handling exceptions?

Is there a way to write this once and have it apply to the entire program? Sure would be nice not to have to write it for each piece.

Perhaps if i put it in a master class file, and then make each proceeding class a subclass of that class?
And can you make a subclass of a subclass?
Jul 2 '07 #1
3 1247
JosAH
11,448 Expert 8TB
I was wondering... you know how java has the ability for us to create a catch throw method for catching and handling exceptions?

Is there a way to write this once and have it apply to the entire program? Sure would be nice not to have to write it for each piece.

Perhaps if i put it in a master class file, and then make each proceeding class a subclass of that class?
And can you make a subclass of a subclass?
It has already been done for you:

Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) {
  2.  
  3. try {
  4.    // your code here
  5. }
  6. catch (Throwable t) {
  7.    // handle all possible exceptions here
  8. }
  9.  
... but it's a very bad idea, i.e. your 'master handler' can't possibly know whatever
went wrong deep down in your code. Better handle exceptions as close to
where they are thrown.

kind regards,

Jos
Jul 2 '07 #2
praveen2gupta
201 100+
I was wondering... you know how java has the ability for us to create a catch throw method for catching and handling exceptions?

Is there a way to write this once and have it apply to the entire program? Sure would be nice not to have to write it for each piece.

Perhaps if i put it in a master class file, and then make each proceeding class a subclass of that class?
And can you make a subclass of a subclass?
hI

Try and Catch block is used close to the exceptions. In a program there may be many try-catch blocks. There are some specific objects and classes which always ask for try-catch block. So it is not an good idea to handle all exceptions of the program at single location.you should use them separately.

It is possible to make subclass of a subclass. In that situation earlier subclass will act as a super class for the latter one.
Jul 3 '07 #3
odefta
18
You can make any subclass of subclass :)
Jul 9 '07 #4

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

Similar topics

10
by: Gary.Hu | last post by:
I was trying to catch the Arithmetic exception, unsuccessfully. try{ int a = 0, b = 9; b = b / a; }catch(...){ cout << "arithmetic exception was catched!" << endl; } After ran the program,...
7
by: Arjen | last post by:
Hi, I'm doing this: try { try { } catch(Exception ex){ throw;
12
by: Andrew Schepler | last post by:
When compiled with Visual C++ .NET 2003 (only), the program below aborts as though no matching catch clause is present. If the copy constructor of A is made public, it successfully catches the...
23
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
3
by: will | last post by:
Hi all. I've got an question about how to catch an exception. In Page_Load, I place a DataGrid, dg1, into edit mode. This will call the method called GenericGridEvent. GenericGridEvent will call...
26
by: Grim Reaper | last post by:
Just a quick and probably daft question... Isn't the code; Try DoSomething() Catch e As Exception HandleError(e) Finally DoThisAtTheEnd()
9
by: Mr Flibble | last post by:
Hi all, happy Friday! (certainly Friday is a day worth celebrating). I have a question on try/catch design (an exciting Friday topic for sure): I can either put a try/catch block in every...
7
by: dick | last post by:
in the "try{throw}catch" structure, how the C++ code return the "type" thrown by a function?
4
by: Fred | last post by:
Is it possible to use throw in javascript without try..catch? As far as I know, you must call it from within a try..catch block, or the function that calls throw must itself be called from within...
4
by: Elmo Watson | last post by:
I've got one main method, with a Try Catch block. In that, I catch the error and put it on a label. However, inside the Try portion, I also run another method. I have a Try/Catch block there,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.