{"record":{"id":"6205e12908599e29","repo":"kunal-kushwaha/DSA-Bootcamp-Java","slug":"name-is-kunal","errorCode":null,"errorMessage":"name is kunal","messagePattern":"name is kunal","errorType":"exception","errorClass":"MyException","httpStatus":null,"severity":"info","filePath":"lectures/17-oop/code/src/com/kunal/exceptionHandling/Main.java","lineNumber":12,"sourceCode":"package com.kunal.exceptionHandling;\n\npublic class Main {\n    public static void main(String[] args) {\n        int a = 5;\n        int b = 0;\n        try {\n//            divide(a, b);\n            // mimicing\n            String name = \"Kunal\";\n            if (name.equals(\"Kunal\")) {\n                throw new MyException(\"name is kunal\");\n            }\n        } catch (MyException e) {\n            System.out.println(e.getMessage());\n        } catch (ArithmeticException e) {\n            System.out.println(e.getMessage());\n        } catch (Exception e) {\n            System.out.println(\"normal exception\");\n        } finally {\n            System.out.println(\"this will always execute\");\n        }\n\n    }\n\n    static int divide(int a, int b) throws ArithmeticException{\n        if (b == 0) {\n            throw new ArithmeticException(\"please do no divide by zero\");\n        }\n","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/kunal-kushwaha/DSA-Bootcamp-Java/blob/6bc4d8bf8ac5e434ac9083e1c01210e42f2a762c/lectures/17-oop/code/src/com/kunal/exceptionHandling/Main.java#L1-L30","documentation":"This is a custom user-defined exception (MyException) thrown explicitly in tutorial code to demonstrate creating and throwing your own exceptions. It fires when a business-rule condition holds (the name equals \"Kunal\"), mimicking how real libraries signal domain errors. The catch block in main prints e.getMessage(), so the program does not crash.","triggerScenarios":"Running main in com.kunal.exceptionHandling.Main when the local variable name equals \"Kunal\"; the throw is unconditional for that value: throw new MyException(\"name is kunal\").","commonSituations":"Learning/teaching custom exception creation; refactoring this demo into real code and forgetting the throw is a stand-in for a domain check; accidentally reusing MyException with its fixed message elsewhere.","solutions":["Change the condition or the name value so the throw is not reached, if this is unintended.","If it is intended demo behavior, no fix needed — the try/catch already prints the message.","Replace the demo check with a real domain validation for production use."],"exampleFix":"// before\nif (name.equals(\"Kunal\")) {\n    throw new MyException(\"name is kunal\");\n}\n// after\nif (name == null || name.isBlank()) {\n    throw new MyException(\"name must not be empty\");\n}","handlingStrategy":"try-catch","validationCode":"// no pre-call validation required; mirror the business rule to avoid the throw:\nif (!name.equals(\"Kunal\")) {\n    // safe path\n}","typeGuard":null,"tryCatchPattern":"try {\n    // code that may throw MyException\n} catch (MyException e) {\n    System.out.println(e.getMessage());\n}","preventionTips":["Mirror the business rule with a caller-side check before invoking code that throws custom exceptions.","Catch the specific custom type before any broader Exception handler.","Define distinct custom exception types per rule for precise catching.","Replace tutorial demo throws with real validation in production."],"tags":["java","custom-exception","oop","tutorial"],"backgroundTag":"custom-exception-thrown","analyzedSha":"6bc4d8bf8ac5e434ac9083e1c01210e42f2a762c","analyzedAt":"2026-08-31T22:04:22.314Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}