Re: Exception handling



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








Why not:

try {
  // whatever
  // do something 2
} catch (ArrayIndexOutOfBoundsException e) {
  // deal with it, ie do something 1
}
.



Relevant Pages

  • Re: Exception handling
    ... Sharp Tool wrote: ... I want to check if a statement throws an exception. ... if throws ArrayIndexOutOfBoundsException) // compile error ... if an exception is likely to be thrown. ...
    (comp.lang.java.programmer)
  • Re: manually setting selected row in a jtable
    ... Brandon McCombs schrieb: ... private void remove{ ... } catch (ArrayIndexOutOfBoundsException a) { ... Since setSelectionIntervaland removeRowtake the same variable as an argument, and between the 2 methods the variable's value does not change, the exception actually occurs at ...
    (comp.lang.java.gui)
  • Re: Exception handling
    ... >> Sharp Tool ... Like i said I don't want to deal with the exception in the catch claus. ... Prev by Date: ...
    (comp.lang.java.programmer)
  • Re: Exception handling
    ... >> I want to check if a statement throws an exception. ... >> Sharp Tool ... > if an exception is likely to be thrown. ... check if an exception would be thrown directly and explicity. ...
    (comp.lang.java.programmer)
  • Re: Array index
    ... I didn't even read what the actual exception was... ... ArrayIndexOutOfBoundsException though. ... Jon Skeet - ... If replying to the group, please do not mail me too ...
    (microsoft.public.dotnet.languages.csharp)