There is some task that should be performed in parallel (for example, opening a file, reading, writing and closing, there is an order on this ...)
But ... Some task is more like a shopping list, I mean that they may have the desired order, but this is not necessary ... an example when exchanging or downloading independent drivers, etc.
For such tasks, I would like to know the best practices or java templates for managing exceptions.
Simple java way:
getUFO { try { loadSoundDriver(); loadUsbDriver(); loadAlienDetectorDriver(); loadKeyboardDriver(); } catch (loadSoundDriverFailed) { doSomethingA; } catch (loadUsbDriverFailed) { doSomethingB; } catch (loadAlienDetectorDriverFailed) { doSomethingC; } catch (loadKeyboardDriverFailed) { doSomethingD; } }
But what about an exception in one of the actions, but try with the following:
I thought about it, but it seems not very useful to use exceptions. I donβt know if this works, it doesnβt matter, it's really terrible !!
getUFO { Exception ex=null; try { try{ loadSoundDriver(); }catch (Exception e) { ex=e; } try{ loadUsbDriver(); }catch (Exception e) { ex=e; } try{ loadAlienDetectorDriver(); }catch (Exception e) { ex=e; } try{ loadKeyboardDriver() }catch (Exception e) { ex=e; } if(ex!=null) { throw ex; } } catch (loadSoundDriverFailed) { doSomethingA; } catch (loadUsbDriverFailed) { doSomethingB; } catch (loadAlienDetectorDriverFailed) { doSomethingC; } catch (loadKeyboardDriverFailed) { doSomethingD; } }
It seems not difficult to find the best practice for this. I'm still not
thanks for any advice
source share