Re: Exception handling
- From: "Sharp Tool" <sharp.tool@xxxxxxxxxxxxxx>
- Date: Sun, 30 Oct 2005 11:21:58 GMT
> Sharp Tool wrote:
> > 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
>
> only by catching or by using a querying method of some kind to determine
> if an exception is likely to be thrown.
>
> 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.
Actually thats whats I am doing, but i was wondering if you could actually
check if an exception would be thrown directly and explicity.
Sharp Tool
.
- References:
- Exception handling
- From: Sharp Tool
- Re: Exception handling
- From: Andrew McDonagh
- Exception handling
- Prev by Date: Re: Exception handling
- Next by Date: Re: Exception handling
- Previous by thread: Re: Exception handling
- Next by thread: Re: Exception handling
- Index(es):
Relevant Pages
|