Java program running in the event of an exception is not processed, will be thrown into the Java Virtual machine for processing, the program is suspended after the run, the page output error message (not output to the console)

Source: Internet
Author: User
Tags try catch

In the following code, because I am using the

 for (Iterator<element> i = el.elements (). Iterator (); I.hasnext ();)

The iterator iterates through the flag of all the child nodes of the root node, but because the Linux baseline has a <initcmd> node that causes flag to be empty,

Throwing an exception while the database operation is in the incoming service causes the program to be suspended, the error message is not output to the console and printed directly to the page.

The workaround is that the try catch handles the exception and returns false.

     Public BooleanIsfound (String xcwindex) {Try{Xconfiglinuxexample Example=Newxconfiglinuxexample (); Xconfiglinuxexample.criteria Criteria=Example.createcriteria ();            Criteria.andxcwindexequalto (Xcwindex); LongCount =Xconfiglinuxmapper.countbyexample (example); returnCount > 0; }Catch(Exception e) {//System.out.println ("Xcwindex is empty, when not traversed to flag");            return false; }    }



     Public voidGetsystypebyuuid (String uuid)throwsIOException, documentexception {Switch(UUID) { Case"66c221be-6ab2-ef53-1589-fe16877914e2"://WindowsImportdataxml ("66c221be-6ab2-ef53-1589-fe16877914e2"); Break;  Case"66c221be-6ab2-ef53-1589-fe16877914f4"://Linux Linux systems need to remove <initcmd> interferenceLinuxbaseline ("66c221be-6ab2-ef53-1589-fe16877914f4"); Break; }    }

     Public voidLinuxbaseline (String uuid)throwsdocumentexception, IOException {jsonobject jsonobject=NewJsonobject (); String result=NULL; Comptools Comptools=NewComptools (); String Path= "c:\\rm-root\\upload\\assetsconfresultxml\\" +Uploadedfilename;//creating the DOM4J parserSaxreader reader =NewSaxreader (); Document Document= Reader.read (NewFile (path)); Element Root=document.getrootelement (); List<Element> elements =root.elements ();        String Flag;        String Xcwvalue; Integer Nonecomplianceconfcount= 0;  for(Element el:elements) { for(Iterator<element> i =el.elements (). iterator (); I.hasnext ();) {element element=(Element) i.next (); Flag= Element.attributevalue ("Flag"); if(Xconfiglinuxservice.isfound (flag)) {Xconfiglinux Allbyxcwindex=xconfiglinuxservice.getallbyxcwindex (flag); Xcwvalue= Element.element ("cmd"). Element ("value")). GetText (); Result=Comptools.linuxcomp (Allbyxcwindex.getcindex (). toString (), Flag, Xconfiglinuxservice, xcwvalue);                    Jsonobject.put (flag, result); if("1". Equals (Result)) {Nonecomplianceconfcount+=1; }                } Else {//System.out.println ("Not Found:" +flag);}}} assetsservice.saveassetsdata (originalfilename,jsonobject,nonecompliance    CONFCOUNT,UUID); }

Java program running in the event of an exception is not processed, will be thrown into the Java Virtual machine for processing, the program is suspended after the run, the page output error message (not output to the console)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.