Numeric Exception in D365 - X++ Code
Table of Content:
Numeric Exception in D365 - X++ Code
try and catch block
class ExceptionHandling { public static void main(Args ar) { int x, y, z; x = 10; y = 0; try { z=x/y; Info(strFmt("%1",z)); } catch (Exception::Numeric) { Info("numeric exception"); } } }
Output:
Multiple catch - With throw block
class ExceptionHandling { public static void main(Args ar) { int x,y; x = 10; y = 30; try { if (x < y) throw Exception: :Warning: } catch(Exception::warning) { warning("x is less"); } catch (Exception::error) { error("x is less"); } catch(Exception::info) { info("x is less"); } } }
Output:
retry
class ExceptionHandling { public static void main(Args ar) { int x,y; x = 10; y = 30; try { if (x < y) throw Exception: :error: Info(strFmt("%1",x)); } catch(Exception::warning) { warning("x is less"); } catch (Exception::error) { error("x is less"); x = 40; retry; } catch(Exception::info) { info("x is less"); } } }
Output: It will print 40
finally Block
class ExceptionHandling { public static void main(Args ar) { int x,y; x = 10; y = 30; try { if (x < y) throw Exception: :error: Info(strFmt("%1",x)); } catch(Exception::warning) { warning("x is less"); } catch (Exception::error) { error("x is less"); } catch(Exception::info) { info("x is less"); } finally { Info("final block"); } } }
Output: