Input Format
A single string, .
  • , where  is the length of string .
  •  is composed of either lowercase letters (or decimal digits ().
Output Format
Print the parsed integer value of , or Bad String if  cannot be converted to an integer.
Exception String to Integer problem solution 30 days of code HackerRank

Problem solution in c++ programming language.

function main() {
    const S = readLine();
    try {
        const N = Number(S);
        isNaN(N) && not_defined_func();
    } catch (err) {
        console.log('Bad String');

Problem solution in Java programming language.

public class Solution {

    public static void main(String[] args) {
        try(Scanner scan = new Scanner(;){
            System.out.println( Integer.parseInt(scan.nextLine()) );
        catch(NumberFormatException e){
            System.out.println("Bad String");

Problem solution in Python programming language.

import sys

S = input().strip()

    S = int(S)
    print("Bad String")