Re: Exception handling
- From: Andrew McDonagh <news@xxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 30 Oct 2005 11:02:19 +0000
Sharp Tool wrote:
only by catching or by using a querying method of some kind to determine if an exception is likely to be thrown.Hi,
I want to check if a statement throws an exception. If it does, I want to deal with it then and there, and not at the catch claus. See code below:
.... String[] str = {"dinner"}; if (str[1].charAt(0) throws ArrayIndexOutOfBoundsException) // compile error { //do something 1 } else //do something 2
Is this possible?
Sharp Tool
e.g
instead of ...
if (str[1].charAt(0) throws ArrayIndexOutOfBoundsException) // compile error
do...
if (str.length > 0) str[1].charAt(0)
This way - no ArrayIndexOutOfBoundsException will be thrown because of the length is too small we don't try and get the first element.
Google 'writing Exception Safe code' .
- Follow-Ups:
- Re: Exception handling
- From: Sharp Tool
- Re: Exception handling
- References:
- Exception handling
- From: Sharp Tool
- Exception handling
- Prev by Date: Executing application on PC from cell phone
- Next by Date: Re: Generics - good, bad or indifferent?
- Previous by thread: Exception handling
- Next by thread: Re: Exception handling
- Index(es):
Relevant Pages
|
|